Referencing Cloned Objects

Talon
01 Jun 2016, 16:45
Been a while since i posted here, but coming on a problem I keep running into, have a vending machine sort of device that is spiting out figurines of various species, I'd like to be able to give these to a NPC and if a certain one is used they'll get a reward..

I'm using the guide here
viewtopic.php?f=18&t=6263&p=42445&hilit=cloned+objects#p42445

for getting the generation going and having the alias's with all the names right, species attributes of each instance set fine when looking through the debugger.

My problem is I'm unable to figure out how to get the NPC to check attributes on whatever clone instance is given him, The player will not know which number it happened to be. the Lion figurine could be figurine1 or figurine 21 afterall

Is there some way to let a script look for a range of object types, such as figurine# perhaps and if one with the proper attribute is founf more on?
Or is there a way i can get the give function to just look at the object being used to trigger the action.. something like "This" perhaps

jaynabonne
02 Jun 2016, 11:02
If you mean the object the script is called on, then you're close: it's "this" (lower case). :)

Talon
02 Jun 2016, 12:52
Had tried that but didn't work, let me try the code posting thing since its a simple enough pair to use it on. I'm putting it as a "give this object(Npc)" handled individually. just want one person to accept the figurine afterall


The figurine itself(object being cloned)
if (this.species = Lion) {
msg ("Thank you for that figurine, its just what i was looking for")
RemoveObject (this)
}
else {
msg ("Nope, don't need that one")
}


I get back the error
Error running script: Error compiling expression 'this.species = Lion': Unknown object or variable 'Lion'

When i look at the right instance of the figure on the debugger it comes up properly with species Lion attribute so at least that part seems to be settling right, as well as the alias name

The Pixie
02 Jun 2016, 13:07
The best way is probably to have the script on the figurine (i.e., set this up on the Use/Give tab of the figurine, rather than the NPC). You do not need to test if the species is right; it is on the lion one, so it must be. Each clone will have it too.

jaynabonne
02 Jun 2016, 13:07
Perhaps you mean this, with it as a string:

if (this.species = "Lion") {
msg ("Thank you for that figurine, its just what i was looking for")
RemoveObject (this)
}
else {
msg ("Nope, don't need that one")


Otherwise, Lion would need to be an object.

Talon
02 Jun 2016, 13:28
..... I always seem to be messed up with the quotes in expressions, when to use them and when not to, had already set it as a string, so after some fiddling managed to get it to work.. Thank you for your help, now to expand the item generation from just two types of animals for the test to rather alot more in the vending machine

HegemonKhan
03 Jun 2016, 01:53
a Value in double quotes is a String Value, which means that its Attribute must be a String Attribute, and the same applies if you're comparing, if one Value/Attribute is a String, than the other Value/Attribute being compared to, must also be a String.

The Attribute Types must match up

another example:

(quest can determine what Attribute Type it is from the syntax of the Value)

game.sample = 5
game.sample = game.sample + 3
// NO error: game.sample = 5 + 3 = 8

game.sample = "5"
game.sample = game.sample + 3
// ERROR: can't add a string and an integer amount together as it's sum doesn't exist, see below (the 'mama' and etc examples)

game.sample = 5
game.sample = game.sample + "3"
// ERROR: can't add a string and an integer amount together as it's sum doesn't exist, see below (the 'mama' and etc examples)

game.sample = "mama"
game.sample = game.sample + 3
// ERROR: can't add a string and an integer amount together as it's sum doesn't exist: mama + 3 = HUH!!!! (sum does not exist, lol)

game.sample = "mama"
game.sample = game.sample + "3"
// NO error: game.sample = "mama" + "3" = "mama3"

game.sample = "3"
game.sample = game.sample + "mama"
// NO error: game.sample = "3" + "mama" = "3mama"

game.sample = "mama"
game.sample = game.sample + "mia"
// NO error: game.sample = "mama" + "mia" = "mamamia"

game.sample = "mama "
game.sample = game.sample + "mia"
// NO error: game.sample = "mama(space)" + "mia" = "mama mia"

game.sample = "mama"
game.sample = game.sample + " mia"
// NO error: game.sample = "mama" + "(space)mia" = "mama mia"

game.sample = "mama"
game.sample = game.sample + " "
game.sample = game.sample + "mia"
// NO error:
// game.sample = "mama" + "(space)" = "mama(space)"
// game.sample = "mama(space)" + "mia" = "mama mia"

game.sample = "5"
game.sample = game.sample + "3"
// NO error (concatenation, literally putting together/next-to-each-other, is occuring, not addition): "53" // a string, not 53 the int amount

game.sample = 5
game.sample = game.sample + 5
// NO error: game.sample = 5+5 = 10

game.sample = "5"
game.sample = game.sample + "5"
// NO error: game.sample = "5"+"5" = "55"

game.sample = 55
game.sample = game.sample + 55
// NO error: game.sample = 55+55 = 110

game.sample = "55"
game.sample = game.sample + "55"
// NO error: game.sample = "55"+"55" = "5555"

-----------

a (non-numeric) Value without double quotes, is an Object Value, and the Attribute must be an Object Attribute

<object name="sword">
</object>
player.right_hand = sword // 'sword' is a reference to an actually existing/created Object { existence/creation: <object name="sword"></object> } in the game, and the Attribute (is / must be) an Object Attribute
// NO error

player.right_hand = sword
// ERROR: there is no existing/created 'sword' Object

player.right_hand = "sword"
// NO error: 'sword' is just a string (text), it's NOT a reference to an actual Object, and the Attribute (is / must be) a String Attribute

--------

the exception of a (non-numeric) Value with no double quotes, in NOT being a reference to an actual Object, is:

the special/reserved keywords of 'true' and 'false', as these are used for Boolean Attributes' Values, 'true' and 'false' are NOT references to an actual Object, lol.

orc.dead = true // Boolean (Value and Attribute)
orc.dead = false // Boolean (Value and Attribute)

jaynabonne
03 Jun 2016, 06:34
Another example of a non-numeric value not being an object reference is a variable.

Lion = "Lion"
if (this.species = Lion) {

jaynabonne
03 Jun 2016, 06:38
There's also null.

HegemonKhan
04 Jun 2016, 01:41
and there's also the special 'this' keyword as a dynamic Object reference/Script/Function (however 'this' is programmed in/works), so it's a bit different too, than a normal specific single object reference. Also, parameters/arguments might be part of these exceptions too. Thanks for including those other exceptions, as I was just thinking about the Booleans as exceptions to it, but forgot there's these others too.