Page 1 of 1

insertItem

Posted: Thu Feb 22, 2018 8:54 pm
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.

Re: insertItem

Posted: Thu Feb 22, 2018 9:38 pm
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

Re: insertItem

Posted: Sat Feb 24, 2018 3:24 pm
by RayB
Thank you. Works great. But if you are trying to delay the event, why the zero time on the delayedCall?

Re: insertItem

Posted: Sat Feb 24, 2018 5:21 pm
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.

Re: insertItem

Posted: Tue Mar 06, 2018 10:12 pm
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.