Hello,
I've started modding and was having an issue with my spawn script.
function spawntest()
spawn("spider", 1, 4, 18, 0):addItem(spawn("brass_key"))
end
something about the additem part is wrong because if I remove it the spider spawns as expected. With the code it says - attempt to call method 'addItem' (a nil value)
Any ideas?
Thanks
additem
Re: additem
Read the scripting reference. This isn't Grimrock 1; spawn() won't return a Monster, it returns a GameObject, which is a container for Components. You need to call MonsterComponent:addItem() on the object's MonsterComponent, not the parent GameObject. Similarly, you need to pass an ItemComponent to MonsterComponent:addItem(), not a GameObject, even if that GameObject happens to contain an ItemComponent.
Also remember to specify elevation in your spawn call.
You can find a more complete list of Component methods here, although it is still missing some.
Also remember to specify elevation in your spawn call.
Code: Select all
spawn("spider",1,4,18,0,0).monster:addItem(spawn("brass_key").item)Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: additem
The scripting model in LoG2 is an unexpected change, and confuses many on their first attempts; coming from Grimrock 1. On the plus side, the system is far more powerful and versatile. On the downside... Much of what one thinks they know [from experience with LoG1], does not work in LoG2 without modification. Foremost: all game objects now contain component functionality. Buttons have a button component, floor plates have a floor_trigger component... and even the party has a "party" component; which means that interaction with the champions looks like this: party.party:getChampion(1)
One of the best things you can do first, is to download the Grimrock 2 asset pack, and read the contained scripts. It shows how the official asset behaviors are scripted.
One of the best things you can do first, is to download the Grimrock 2 asset pack, and read the contained scripts. It shows how the official asset behaviors are scripted.