Page 1 of 1

Script in Normal Game

Posted: Sun Nov 02, 2014 4:50 pm
by Zanzer
I'm fooling around with scripts in the console while playing the normal game.

I can't seem to get my script to execute.

I'm creating my timer:

Code: Select all

spawn("timer",nil,nil,nil,nil,nil,"ztimer")
ztimer.timer:setTimerInterval(1)
ztimer.timer:setDisableSelf(false)
ztimer.timer:setTriggerOnStart(false)
ztimer.timer:setCurrentLevelOnly(false)
ztimer.timer:addConnector("onActivate","zscript","zanzer")
And then I create my script entity:

Code: Select all

spawn("script_entity",nil,nil,nil,nil,nil,"zscript")
zscript.script:setSource("function zanzer()hudPrint('test')end")
I know the timer works, because I get the following warning if I don't spawn the script entity:

Code: Select all

warning! invalid connector target: zscript
I just can't get it to print any messages.

Re: Script in Normal Game

Posted: Sun Nov 02, 2014 7:20 pm
by JohnWordsworth
I don't know if script:setSource() actually runs the code. I have a gut instinct that possibly setSource will set a property on the script entity, but then the code within a script entity is only run when the dungeon first starts... Not sure, but that's one possible reason for why it doesn't work!

Re: Script in Normal Game

Posted: Sun Nov 02, 2014 8:16 pm
by Zanzer
On another note, the following code also does not run the script.

Code: Select all

delayedCall("zscript",1,"zanzer")
If you specify an invalid function name, for example:

Code: Select all

delayedCall("zscript",1,"notzanzer")
Then the system produces the warning:

Code: Select all

warning! invalid message: zscript.notzanzer
So, it does seem to know that the script contains a function called "zanzer". It simply does not print the message.

Re: Script in Normal Game

Posted: Sun Nov 02, 2014 8:25 pm
by NutJob
Are you running the delayedCall from an external script? I had to do some hackery to make that work. Basically call some catalyst script outside your library, and to send parameters assign them to a global table that expire (nil) after you used the variables.

Anyways, are you calling from an external script?

Re: Script in Normal Game

Posted: Sun Nov 02, 2014 9:22 pm
by Zanzer
I am calling everything directly from the console within the game. No files. No DAT.

Re: Script in Normal Game

Posted: Sun Nov 02, 2014 9:26 pm
by AdrTru
I have a problem with delayedCall function. Idea is super to use simple trigger without timer component, but there is problem with nil sending values.
e.g.

Code: Select all

function testDelay()
  delayedCall("zscript",1,"zanzer")
end
-->>
function zanzer(test)
  print(test)     -- nil value.
end
Becouse delayCall is not component it havent id ....
Can is possible to make there some parameter like another triggers?

Re: Script in Normal Game

Posted: Tue Nov 04, 2014 6:13 am
by Zanzer
I wasn't trying to pass an argument. I simply wanted it to print the text "test".

This all works fine when done inside a custom dungeon.

It just doesn't want to work when done dynamically through the console.