Script in Normal Game

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
Zanzer
Posts: 8
Joined: Sun Nov 02, 2014 4:38 pm

Script in Normal Game

Post 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.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: Script in Normal Game

Post 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!
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Zanzer
Posts: 8
Joined: Sun Nov 02, 2014 4:38 pm

Re: Script in Normal Game

Post 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.
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Script in Normal Game

Post 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?
Zanzer
Posts: 8
Joined: Sun Nov 02, 2014 4:38 pm

Re: Script in Normal Game

Post by Zanzer »

I am calling everything directly from the console within the game. No files. No DAT.
User avatar
AdrTru
Posts: 223
Joined: Sat Jan 19, 2013 10:10 pm
Location: Trutnov, Czech Republic

Re: Script in Normal Game

Post 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?
My LOG2 projects: virtual money, Forge recipes, liquid potions and
MultiAlcoveManager, Toolbox, Graphic text,
Zanzer
Posts: 8
Joined: Sun Nov 02, 2014 4:38 pm

Re: Script in Normal Game

Post 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.
Post Reply