Author Topic: script-eval  (Read 2551 times)

0 Members and 1 Guest are viewing this topic.

Offline CP5670

  • Dr. Evil
  • Global Moderator
  • 212
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.

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
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.
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline CP5670

  • Dr. Evil
  • Global Moderator
  • 212
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.

  

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
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...
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline CP5670

  • Dr. Evil
  • Global Moderator
  • 212
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?

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
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
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline CP5670

  • Dr. Evil
  • Global Moderator
  • 212
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

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
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
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline CP5670

  • Dr. Evil
  • Global Moderator
  • 212
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

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Stable branch scripting is unsupported. Try adding "[" and "]" (without the quotation marks) around the script, so:

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

 

Offline CP5670

  • Dr. Evil
  • Global Moderator
  • 212
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.

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Try adding "[" and "]" (without the quotation marks) around the script, so:

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

Yay! That worked.
Do not meddle in the affairs of coders for they are soggy and hard to light