need help ' onUseItem '

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Pandafox
Posts: 268
Joined: Wed Apr 11, 2012 11:25 pm
Location: France
Contact:

Re: need help ' onUseItem '

Post by Pandafox » Sun Feb 03, 2013 7:02 pm

Need help again :?

Code: Select all

function chaos_wall_destroy()
	local nameteleporter = "tele"..counter_chaos:getValue()
	print ("dest "..nametele)
	nameteleporter:destroy()
end
Here, I have a function which must destroy a teleporter.
The teleporter was created before by script. The id of this teleporter is "tele"..counter_chaos:getValue()
I increment a counter each time a teleporter is created to have a different name.

The names of the teleporters are tele1, tele2, tele3 ... ...
(no problem with that)

But when I want to destroy it using the name I make dynamicly, it don't works :cry:

User avatar
crisman
Posts: 305
Joined: Sat Sep 22, 2012 9:23 pm
Location: Italy

Re: need help ' onUseItem '

Post by crisman » Sun Feb 03, 2013 7:45 pm

try this:

Code: Select all

function chaos_wall_destroy()
local nameteleporter = findEntity("tele"..counter_chaos:getValue())
print ("dest "..nametele)
nameteleporter:destroy()
end
The reason is because you are actually trying to call an entity with a string, findEntity will turn a string into an entity :)
Or whatever... :mrgreen:

User avatar
Pandafox
Posts: 268
Joined: Wed Apr 11, 2012 11:25 pm
Location: France
Contact:

Re: need help ' onUseItem '

Post by Pandafox » Mon Feb 04, 2013 2:32 pm

thanks for help, it works now :)

I have a new question :

do you know how to send parameters to the function called here :
timer:addConnector("activate", "chaos_wall_script", "chaos_wall_dest")

The script id is "chaos_wall_script", the function of this script is "chaos_wall_dest" but I need to send a parameter to this function..?

User avatar
Komag
Posts: 3637
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: need help ' onUseItem '

Post by Komag » Mon Feb 04, 2013 4:15 pm

If you have a timer in between and it's the timer that triggers the function, then the only way I know of is to have the earlier script set a flag/variable and have the new function first check that variable
Finished Dungeons - complete mods to play

Post Reply