I am certain this has already been answered but my searchfu is failing.
I am trying to script items to spawn onto the surface of an alcove when the key is entered into a nearby lock.
I have everything connected correctly and the key runs the correct script but when the script runs I get the following:
dungeon_alcove_1.surface:addItem(xafi_khakis.item) <<attempt to index global 'xafi_khakis' (a nil value)>>
As far as I can tell I copied the addItem code exactly as found in several tutorial posts. Thank you in advance for any assistance.
*EDIT: I've also tried using the .spawn("xafi_khakis") and I also get an error.
addItem issue
-
- Posts: 12
- Joined: Sat Oct 25, 2014 3:26 pm
Re: addItem issue
I'm not sure about alcoves but I know when doing addItem into an inventory you can't just use the item, you have to give it a position.
So like:
party.party:getChampion(1):insertItem(13, pellet_box_1.item)
where 13 is the 1st characters top leftmost backpack slot. Followed by the item and then declaring it as an item. Also I don't think addItem will work if the item in question doesn't already exist somewhere else in the level(most likely why you get the nil value error). You could get around that by just having a 1x1 room off in a corner somewhere inaccessible that has the item already inside it. Hope this helps somewhat, I have been largely stonewalled trying to get items into inventories or even just using spawn commands personally. 2 hard 4 meh.
So like:
party.party:getChampion(1):insertItem(13, pellet_box_1.item)
where 13 is the 1st characters top leftmost backpack slot. Followed by the item and then declaring it as an item. Also I don't think addItem will work if the item in question doesn't already exist somewhere else in the level(most likely why you get the nil value error). You could get around that by just having a 1x1 room off in a corner somewhere inaccessible that has the item already inside it. Hope this helps somewhat, I have been largely stonewalled trying to get items into inventories or even just using spawn commands personally. 2 hard 4 meh.
Re: addItem issue
Does this work:
Code: Select all
dungeon_alcove_1.surface:addItem(spawn("xafi_khakis").item);
Re: addItem issue
I've been playing around with this and so far I can't get the addItem to work unless the item is already on the level. At first I was placing them on the map in side areas where the player couldn't get. Then I discovered the spawn command and combined them into two lines in my script:
This works and I don't have to have the item placed pre-existing on the level. So my final function looks like this:
This snippet makes the lock disappear and an alcove appear in a specific location with a specific set of items. Right now it's instant and 'magical' but I'm going to add a hudPrint and am trying to figure out how to make a sound play too.
Code: Select all
spawn("xafi_khakis",level,0,0,0,0,"xafi_khakis_1")
dungeon_alcove_1.surface:addItem(xafi_khakis_1.item)
Code: Select all
function GoldLockRewardOne()
spawn("dungeon_alcove",level,11,4,0,0,"alcove_gold_reward_1")
spawn("xafi_khakis",level00,0,0,0,0,"xafi_khakis_1")
spawn("xafi_robe",level00,0,0,0,0,"xafi_robe_1")
spawn("sandals",level00,0,0,0,0,"sandals_1")
spawn("cutlass",level00,0,0,0,0,"cutlass_1")
alcove_gold_reward_1.surface:addItem(xafi_khakis_1.item)
alcove_gold_reward_1.surface:addItem(xafi_robe_1.item)
alcove_gold_reward_1.surface:addItem(sandals_1.item)
alcove_gold_reward_1.surface:addItem(cutlass_1.item)
lock_gold_reward_1:destroy()
end
Re: addItem issue
@ScroLL - Of course I go an post my fix before trying your code. Much more elegant and worked fine.
ScroLL wrote:Does this work:
Code: Select all
dungeon_alcove_1.surface:addItem(spawn("xafi_khakis").item);