Page 2 of 2

Re: Adding items to a spawned entity

Posted: Thu Nov 08, 2012 7:00 pm
by Komag
addItem almost always has to be followed by a spawn command :)

Re: Adding items to a spawned entity

Posted: Thu Nov 08, 2012 8:17 pm
by SpiderFighter
Komag wrote:addItem almost always has to be followed by a spawn command :)
I had no way of knowing that...in the official scripting reference it says "Monster:addItem(item)" :)

Re: Adding items to a spawned entity

Posted: Thu Nov 08, 2012 8:48 pm
by Komag
I know, it would best if it were noted there, many of us ran into the same problem.

The thing is, it needs an actual item, not just an item name, which is what you put. Any item in the game that has been created has it's own "itemness" (a code or hex or number or something, I'm not sure, call it "ether") and two useful identifiers, a name, and an id. The name is the type of item it is. The id is the useful identifier for that particular item, but is not the same as the item's "ethereal" self.

Anyway, that script needs an actual item, not a name or even an id, and the only way to really access an item is to create one on the spot

Re: Adding items to a spawned entity

Posted: Thu Nov 08, 2012 9:31 pm
by Komag
Try these functions to see more about how items really work. Just stick them in a script entity and link a couple buttons or pressure plates to them.

Code: Select all

function makeRock()
  spawn("rock", party.level, party.x, party.y, 0, "myRock")
  print(myRock)
  print(myRock.id)
  print(myRock.name)
end
this one can only be done once, because if you try to do it again you'll get a crash due to the fact that you already made a rock with the id myRock and there can be only one. But it does illustrate the three different identifiers of what a rock is in the game's mind

Code: Select all

function whatRock()
  local thisRock = spawn("rock", party.level, party.x, party.y, 0)
  print(thisRock)
  print(thisRock.id)
  print(thisRock.name)
end
This one can be done infinite times, and you'll notice that the game keeps assigning a higher and higher id number for each new rock you create.