Need Script to Recognize an Object's Alias
MikeOmega
14 Sept 2012, 17:02I keep running into this problem... In my game, I have a series of objects which I am using as spells. I have a command which allows the player to cast a spell given that spell object is contained within a hidden object, the player's spellbook. My problem is, when a player learns a new spell, the original spell object is cloned and moved to their spellbook. Say we're using a spell named "blind". This changes the object's name to "blind1" as it is a duplicate of an already existing object. There are other parts of the game where that object has already been cloned, so now the object's name is "blind2" or "blind3". So I can't have the game check for a specific name. I need a way for the game to check the spell book for the object's alias instead, which is "Blind". Is there a way to do this?
Another similar note, I am working with another script which would end the game when the player's health reaches 0, but not if the player is carrying a specific item in their inventory. I am calling this item "phoenix" right now, if the player's health reaches 0 and the object "phoenix" is in their inventory, then it restores their health and the game does not end. I tried this with a "for each" script, which checks the player's inventory. I hit the same problem with the first, It can only search for the specific "phoenix" object rather than a clone, say "phoenix1" or "phoenix2". And if the player is carrying more objects in their inventory than just the "phoenix" then it runs the script on them as well, because they are not "phoenix" and ends the game. How can I fix it so that it searches for the alias "Phoenix" and only ends the game if the player lacks it?
How do I fix this?
Another similar note, I am working with another script which would end the game when the player's health reaches 0, but not if the player is carrying a specific item in their inventory. I am calling this item "phoenix" right now, if the player's health reaches 0 and the object "phoenix" is in their inventory, then it restores their health and the game does not end. I tried this with a "for each" script, which checks the player's inventory. I hit the same problem with the first, It can only search for the specific "phoenix" object rather than a clone, say "phoenix1" or "phoenix2". And if the player is carrying more objects in their inventory than just the "phoenix" then it runs the script on them as well, because they are not "phoenix" and ends the game. How can I fix it so that it searches for the alias "Phoenix" and only ends the game if the player lacks it?
if (player.health <= 0) {
if (Got(phoenix)) {
msg ("You nearly succumb to your wounds... But before your vision fades for the last time, you feel a burning heat radiating from your pouch. A powerful energy washes over you as the Phoenix Phylactory you were carrying uses its magic to restore your life! As the vitality fills you, the amulet, having been drained of its energy, shatters!")
MoveObject (object, junk)
player.health = player.maxHP
}
else {
msg ("You have been slain!")
finish
}
How do I fix this?

Pertex
14 Sept 2012, 18:35Perhaps this function can help. It searches an object or his cloned brothers under the specific parent .
obj1=findObject(spellbook,blind)
if (obj1 <> null) {
// do something
}
<function name="findObject" parameters="parent, searchObj" type="object"><![CDATA[
result = null
lenSearchObj = LengthOf(searchObj.name)
foreach (obj, AllObjects()) {
if (obj.parent=parent) {
len = LengthOf(obj.name)
if (len>=lenSearchObj and UCase(Left(obj.name,lenSearchObj))=UCase(searchObj.name)) {
result = obj
}
}
}
return (result)
]]></function>
The Pixie
14 Sept 2012, 18:51If I was doing it, rather than cloning, I would move the object to the spellbook, or whatever, then check where that specific object is.

jaynabonne
14 Sept 2012, 20:37A variation on the theme that Pertex posted would be to search for the original prototype object differently - by storing it in the clone itself for easy access.
When you clone an object (creating "newObj" from "prototypeObj"), you can then do something like:
Then instead of some questionable name (or alias) munging, you can just do a comparison:
When you clone an object (creating "newObj" from "prototypeObj"), you can then do something like:
newObj.prototype= prototypeObj
Then instead of some questionable name (or alias) munging, you can just do a comparison:
<function name="findObject" parameters="parent, prototypeObj" type="object"><
jaynabonne
15 Sept 2012, 09:07I had made an assumption that, given the use of cloning, there could be multilple instances of the same spell in play at once. If not, then certainly reusing the same object makes more sense. 

sgreig
15 Sept 2012, 18:30Yeah, that's what I was thinking as well. Unfortunately, the OP doesn't really specify why he's choosing to clone the items, so it's hard to say for sure until he clues us in. 

MikeOmega
18 Sept 2012, 16:49My apologies, I have been away for a few days. Let me provide some clarification.
I'm trying to make my game highly dynamic and highly variable, where each little action of the players, from character creation onwards, creates a distinctly unique playing experience.
The reason I am cloning the objects is because the object in question needs to be available at multiple points in the game, and will be in the inventory of multiple characters simultaneously. In the case of spells, they are either given to the player when they start the game or later on if they choose to purchase one from a merchant. To me, it makes more sense to clone the object and move it than to make a million or so objects which would have to be sorted. And if I would like other character objects in the game to be holding that identical spell object, it would necessitate cloning from a prototype spell object, yes?
I believe the issue is that I have vendors who sell items and spells in my game. When the player chooses an option from a list of what to buy, the game clones a prototype object and moves it to the player's inventory, that way not every single vendor has to have their own complete inventory of objects, and that objects can be purchased multiple times.
I'm having a bit of trouble incorporating the code given into my game... I'm not sure what I'm doing wrong here. I've tried implementing it as a function, but I keep getting errors. How do I go about setting this up in Quest's interface?
I'm trying to make my game highly dynamic and highly variable, where each little action of the players, from character creation onwards, creates a distinctly unique playing experience.
The reason I am cloning the objects is because the object in question needs to be available at multiple points in the game, and will be in the inventory of multiple characters simultaneously. In the case of spells, they are either given to the player when they start the game or later on if they choose to purchase one from a merchant. To me, it makes more sense to clone the object and move it than to make a million or so objects which would have to be sorted. And if I would like other character objects in the game to be holding that identical spell object, it would necessitate cloning from a prototype spell object, yes?
I believe the issue is that I have vendors who sell items and spells in my game. When the player chooses an option from a list of what to buy, the game clones a prototype object and moves it to the player's inventory, that way not every single vendor has to have their own complete inventory of objects, and that objects can be purchased multiple times.
I'm having a bit of trouble incorporating the code given into my game... I'm not sure what I'm doing wrong here. I've tried implementing it as a function, but I keep getting errors. How do I go about setting this up in Quest's interface?
sgreig
18 Sept 2012, 23:09Ok, I see what you're getting at. Maybe there's a simpler solution? How about instead of having multiple instances of the spell objects, use flags instead? For example, and assuming I've understood the premise of how spells work in your game, you have the spell book object, and when you add these gems or crystals or whatever the objects are to the spell book, you gain the ability to cast a specific spell?
What you could do instead of cloning the objects, is when a spell object is acquired either through loot drops or purchase from a vendor, is that a flag is set on the spellbook object, and the physical object is moved to a sort of "limbo" room outside of the playable area of the game. You wouldn't see the objects in the list of inventory items in the panel, but you could have a dynamic description of the spell book that tells the player what spell objects they have. This probably isn't exactly how you envisioned it, but this is the simplest way I can think of to implement what you're talking about.
What you could do instead of cloning the objects, is when a spell object is acquired either through loot drops or purchase from a vendor, is that a flag is set on the spellbook object, and the physical object is moved to a sort of "limbo" room outside of the playable area of the game. You wouldn't see the objects in the list of inventory items in the panel, but you could have a dynamic description of the spell book that tells the player what spell objects they have. This probably isn't exactly how you envisioned it, but this is the simplest way I can think of to implement what you're talking about.

jaynabonne
18 Sept 2012, 23:44Mike, if you could post what you're trying that's giving you errors, it might help. I understand what you're doing generally, and it more or less makes sense, but I can't offer any guidance on the specifics without seeing something... specific. 


Pertex
19 Sept 2012, 09:02Mike, open the codeview in the editor, then copy the function to your game, best between the last </object> and </asl>, something like this:

Then you can switch back to the gui and call this function like this:


Then you can switch back to the gui and call this function like this:
