Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: CP5670 on March 05, 2007, 01:57:35 am

Title: script-eval
Post by: CP5670 on March 05, 2007, 01:57:35 am
Can one of you tell me how this sexp works? How is the script specified in it? The sexp description is useless and I can't find anything about it on the wiki.
Title: Re: script-eval
Post by: Wanderer on March 05, 2007, 02:50:40 am
You specify a function in the scripting.tbl and use the script-eval to run the scripted function. There are some big limitations with the string lenght though so you may have to use rather short function names.

Scripting.tbl - probably to gameinit hook
Code: [Select]
function runme()
   ba.error("script-eval test")
end

Would toss an error to the screen and stop (ctd) the game when the 'runme()' function is called via script-eval sexp. So you can build complex lua functions and then execute them via script-evals. Well.. in theory at least.. that is i havent really even tried these.
Title: Re: script-eval
Post by: CP5670 on March 05, 2007, 03:48:06 am
I tried that out, but I can't get it to actually detect the function (the LUA syntax is runme = function() ). The sexp seems to have no effect, although the function works fine if I call it in the HUD hook or something like that.
Title: Re: script-eval
Post by: Wanderer on March 05, 2007, 04:41:43 am
AFAIK you'll have to write the function to the sexp.. it doesnt appear in pulldown menu

And actually Lua is supposed to accept both syntaxes for functions but that isnt important...
Title: Re: script-eval
Post by: CP5670 on March 05, 2007, 08:20:54 am
Yeah, I was entering it in manually, but the game itself didn't seem to recognize it.

Does it need to be placed inside any specific hook in order to work?
Title: Re: script-eval
Post by: Wanderer on March 05, 2007, 09:50:17 am
I tried this one and got only errors

Sexp
Code: [Select]
$Formula: ( when
   ( has-time-elapsed 5 )
   ( script-eval "runme()" )
)
+Name: Script
+Repeat Count: 1
+Interval: 1

Scripting
Code: [Select]
runme = function()
   ba.error("script-eval test")
end

Errors
Code: [Select]
LUA ERROR: [string "runme()"]:1: unexpected symbol near '<eof>'
I even tried to look help from the CVS code but my feeble skills were no match for the dark powers of C
Title: Re: script-eval
Post by: CP5670 on March 05, 2007, 10:30:03 am
At least it's giving you an error. I am trying a very similar thing, but the game doesn't do anything at all. Could you post your entire scripting.tbl?

Quote
Wanderer
Wiki Warrior

Posts: leet

Didn't know the forum software did that. :D
Title: Re: script-eval
Post by: Wanderer on March 05, 2007, 12:39:47 pm
I use new builds from HEAD branch... 20070228.

Full scripting.tbl:
Code: [Select]
#Global Hooks

$GameInit:

[

runme = function()
   ba.error("script-eval test")
end

function metoo()
   ba.error("script-eval test 2")
end

]

#End

And full sexp list
Code: [Select]
#Events     ;! 2 total

$Formula: ( when
   ( has-time-elapsed 5 )
   ( script-eval "runme()" )
)
+Name: Script
+Repeat Count: 1
+Interval: 1

$Formula: ( when
   ( has-time-elapsed 4 )
   ( script-eval "metoo()" )
)
+Name: Scrtest
+Repeat Count: 1
+Interval: 1
Title: Re: script-eval
Post by: CP5670 on March 05, 2007, 01:14:24 pm
It must be a build-specific thing then. I'm using one of the Taylor builds. Does this script-eval sexp work at all in the builds from the stable branch?

I need to get WMC in here... :p
Title: Re: script-eval
Post by: WMCoolmon on March 09, 2007, 03:04:10 am
Stable branch scripting is unsupported. Try adding "[" and "]" (without the quotation marks) around the script, so:

--script-eval
----"[runme()]"
Title: Re: script-eval
Post by: CP5670 on March 10, 2007, 12:45:46 am
I tried that out, but game was throwing up a LUA error with it (something about an invalid string type, the same error I got when I wasn't entering the function parentheses correctly).

The current head builds have a particularly bad bug in them (the pilot file thing), so I'll wait for that to be resolved before trying them out.
Title: Re: script-eval
Post by: Wanderer on March 10, 2007, 02:05:39 am
Try adding "[" and "]" (without the quotation marks) around the script, so:

--script-eval
----"[runme()]"

Yay! That worked.