What is Wrong with this Script?

Error running script: Error compiling expression 'game.sticks_clone + 1': ArithmeticElement: Operation 'Add' is not defined for types 'Element' and 'Int32'

if (RandomChance(90)) {
  game.sticks_clone = CloneObject (Sticks)
  game.sticks_clone = player.parent
  while (RandomChance(50)) {
    game.sticks_clone = game.sticks_clone + 1
  }
  msg ("There are " + game.sticks_clone + " sticks here")

if (RandomChance(90)) {
  game.sticks_clone = CloneObject (Sticks)
  game.sticks_clone.parent = player.parent
  while (RandomChance(50)) {
    game.sticks_clone.quantity = game.sticks_clone.quantity + 1
  }
  msg ("There are " + game.sticks_clone.quantity + " sticks here")

I gave your 'Sticks' Object and your 'game.sticks_clone' Object Attribute, a 'quantity' Integer Attribute, so make sure you do/create/have the same on your 'Sticks' Object --- you can rename it to whatever you want, just make sure that they match up


alternatively, you want might to do this instead (practically the same thing, but its a little better in terms of the coding it uses):

if (RandomChance(90)) {
  game.sticks_clone = CloneObject (Sticks)
  game.sticks_clone.parent = player.parent
  if (RandomChance(50)) {
    game.sticks_clone.quantity = game.sticks_clone.quantity + GetRandomInt (0,5) // you can change the values to whatever
  }
  msg ("There are " + game.sticks_clone.quantity + " sticks here")

Hmm, I think I see. So you cannot apply number attributes to clones themselves?


You can give a clone a number attribute; but you can't treat a clone as if it were a number. You need to name the attribute.


I don't know what mrangel or Enpherdaen are talking about. You can give the same name and value to multiple objects. At least I think that's what was meant by "number attributes."


How do I put the "quantity" attribute on the "sticks" object? Also what does this do?


'Sticks' Object -> 'Attributes' Tab -> Attributes (bottom box) -> Add -> (see below)

Attribute Name: quantity
Attribute Type: int // (integer)
Attribute Value: (whatever you want your initial stick's quantity to be, note that this amount will get copied to your clones' quantities as well, if/when using my scripting code in my post above)

the reason, is so that your clones, will get a 'quantity' Integer Attribute, starting with the value/amount that your original 'Sticks' Object has for its 'quantity' Integer Attribute, and since the clones have the 'quantity' Integer Attribute, the arithmetic:addition operation ( game.sticks_clone.quantity = game.sticks_clone.quantity + 1 ), will hopefully work fine without errors...


Okay, but I have a goal that I hope this will work with: There is a random chance that an object (ex: stick) will spawn in a room. When it does, it has a random quantity assigned to it. When a player "picks up" a the stick, it gets destroyed. However, the invisible stick in the players's inventory becomes visible, and the value of it goes up depending on the value of the stick.

If the player picked up a stick.quantity less than the value of the stick object in the room, then the value of that stick will go down accordingly, and the value of the inventory stick will go up accordingly. It seems pretty simple to me.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums