insertItem

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

insertItem

Post by RayB »

Back again!!
Can anyone tell me why the following code will not work?

party.party:getChampion(3):insertItem(1,spawn("long_sword").item)

A little testing with the print statement tells me the sword was created and (with different code) I can place it directly in front of the party then pick it up but I cannot get it to insert into a champion's hand.
User avatar
Zo Kath Ra
Posts: 944
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: insertItem

Post by Zo Kath Ra »

Did you put it inside a script entity, but outside of any functions?
Doesn't work, probably because it's too early, but I have no idea for what.

This works when put inside a script entity:

Code: Select all

delayedCall(self.go.id, 0, "test")

function test()
	party.party:getChampion(3):insertItem(1,spawn("long_sword").item)
end
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: insertItem

Post by RayB »

Thank you. Works great. But if you are trying to delay the event, why the zero time on the delayedCall?
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: insertItem

Post by Isaac »

In this case, just including the function name would also work.

Code: Select all


function test()
   party.party:getChampion(3):insertItem(1,spawn("long_sword").item)
end

test()

Funny thing is, it works for me with just the base statement.

Code: Select all

   party.party:getChampion(3):insertItem(1,spawn("long_sword").item)
However the editor needs to be restarted each time; there is a certain persistence of state between previews, that only gets reset by a reload.
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: insertItem

Post by RayB »

Some such things worked for me too when place directly in the script but others didn't.

I remember trying to get code to work when placed directly in the script and it wouldn't so I placed a simple print("hello") line into the same script. It still didn't work but 'hello' printed out on the screen so I know the script was run.

The delayedCall(self.go.id, 0, functionName) seems to work fine but even with that sometimes I have to replace the '0' with '0.1' to get it to work.

I think it must have something to do with the order of things in the mod.
Post Reply