Page 1 of 1

Items to Sack to Alcove

Posted: Tue Oct 16, 2012 3:21 pm
by DeDy
Hi, again need help. Easy script in editor F5 function ok. Dungeon Export, Custom Dungeon start all ok. Save game Grimrock shot down.

Code: Select all

function sack01()
	sack01 = spawn("sack")
	alcove_sack01:addItem(sack01)

	flask01 = spawn("flask")
	sack01:addItem(flask01)

	tar01 = spawn("tar_bead")
	sack01:addItem(tar01)

	energy01 = spawn("potion_energy")
	sack01:addItem(energy01)
end
error.log
SpoilerShow
script_entity_16: cannot serialize table 'tar01' with metatable
stack traceback:
[C]: in function 'error'
[string "ScriptEntity.lua"]: in function 'saveValue'
[string "ScriptEntity.lua"]: in function 'saveState'
[string "GameMode.lua"]: in function 'saveGame'
[string "GameMode.lua"]: in function 'quickSave'
[string "GameMode.lua"]: in function 'keyPressed'
[string "Grimrock.lua"]: in function 'pollEvents'
[string "Grimrock.lua"]: in function 'display'
[string "Grimrock.lua"]: in main chunk
Thanks

Re: Items to Sack to Alcove

Posted: Tue Oct 16, 2012 3:43 pm
by crisman
I think it's not working because you have used the name 'sack01' for both the function and for a variable.

Re: Items to Sack to Alcove

Posted: Tue Oct 16, 2012 4:26 pm
by DeDy
crisman wrote:I think it's not working because you have used the name 'sack01' for both the function and for a variable.
no :(
SpoilerShow

Code: Select all

function SackToAlcove1()
	sack_01x = spawn("sack")
	alcove_sack01:addItem(sack_01x)

	flask_01x = spawn("flask")
	sack_01x:addItem(flask_01x)

	tar_01x = spawn("tar_bead")
	sack_01x:addItem(tar_01x)

	energy_01x = spawn("potion_energy")
	sack_01x:addItem(energy_01x)
end

Re: Items to Sack to Alcove

Posted: Tue Oct 16, 2012 4:27 pm
by Lilltiger
Try using "local" in front of the variables, as the game cant handle global vars that contains objects.

Re: Items to Sack to Alcove

Posted: Tue Oct 16, 2012 4:29 pm
by Filipsan
try local variables

Code: Select all

    
function SackToAlcove1()
       local sack_01x = spawn("sack")
       alcove_sack01:addItem(sack_01x)

       local  flask_01x = spawn("flask")
       sack_01x:addItem(flask_01x)

       local  tar_01x = spawn("tar_bead")
       sack_01x:addItem(tar_01x)

       local  energy_01x = spawn("potion_energy")
       sack_01x:addItem(energy_01x)
    end

Re: Items to Sack to Alcove

Posted: Tue Oct 16, 2012 6:01 pm
by crisman
weird. I've tried your code and it's working fine for me.
Have you tested it with only an item per time?

Re: Items to Sack to Alcove

Posted: Tue Oct 16, 2012 9:33 pm
by DeDy
LOCAL test is OK. Thanks

function SackToAlcove1()
local sack_01x = spawn("sack")
alcove_sack01:addItem(sack_01x)

local flask_01x = spawn("flask")
sack_01x:addItem(flask_01x)

local tar_01x = spawn("tar_bead")
sack_01x:addItem(tar_01x)

local energy_01x = spawn("potion_energy")
sack_01x:addItem(energy_01x)
end

Re: Items to Sack to Alcove

Posted: Wed Oct 17, 2012 12:32 pm
by Komag
If you just want this to exist at the start of the map, you can do it more straightforward. Just have your script say:

Code: Select all

local sack_01x = spawn("sack")
alcove_sack01:addItem(sack_01x)
sack_01x:addItem(spawn("flask"))
sack_01x:addItem(spawn("tar_bead"))
sack_01x:addItem(spawn("potion_energy"))
if you really want to trigger it at some later point, just add a "function name()" at the top and an "end" line at the bottom

Re: Items to Sack to Alcove

Posted: Wed Oct 17, 2012 12:58 pm
by DeDy
WOW, script OK, thanks.