Author Topic: fred <-> script interaction  (Read 2124 times)

0 Members and 1 Guest are viewing this topic.

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
fred <-> script interaction
im not entirely sure i know how to make mission events talk to scripts. im wondering if somone could break down how fred and scripts interact. let it be known that im really bad at fredding, as my scannin crates mission can attest.

the other day i wrote this nifty little script to cloak your ship roughly 10 seconds into the game, assuming the proper bitmaps were available. now i didnt mean to get overly involved with designing a cloaking system, i just wanted to show other modders that scripting could probibly do what they wanted. but i was impressed by the effect and thought it feasable to write a script that any modder/fredder could use to cloak and decloak ships using fred's event system.

my script is simple and you have no control over when you cloak, it just cloaks, end of story. it mainly uses texture replacement changing out the ship texures with others of varying transparency. i wrote a function that automatically loads cloakmaps starting with texturename-c## into an array so they can be cycled through rather easily. i also have a function to unload the textures. and im working on a 3rd function to toggle cloak states.

i need to be able to make 3 function calls from fred. the first to specify a ship handel (or something i can derive the handel from like a name or ship index) for the ship which will be cloaking, this tells my script what ship will be cloaking and also loads the textures for that ship on mission start. the next function is for toggeling cloak on and off, giving it the ship thats cloaking and returning wether its cloaked or not. and the 3rd thats used to unload the textures at the end of the mission, so they dont sit in memory and degrade performance (a 16 texture cloak effect on a 512^2 map can take up to 6 megs, and that only multiplies for each texture that the ship has).

anyway i want to make it so all the fredder has to do is (other than making cloak maps) put in 3 events, to init cloaking for a ship, to toggle the cloak, and to unload the textures at mission end. the fredder should be able to make advanced cloaking behavior, such as locking guns, throught the events system. i want to use the events system because of the white-elephant nature fo the effect, and its rather ineffietient use of texture memory forbids using it on every single ship, making it excelent for mission speciffic use.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: fred <-> script interaction
You can use the script-eval sexp to call specific scripting functions.

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

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

Mission file
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 6 )
   ( 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 WMCoolmon

  • Purveyor of space crack
  • 213
Re: fred <-> script interaction
There's a 32-character limit on whatever you put in the script-eval SEXP, due to the limitations of the SEXP system. (:p)

But you can get at FRED variables from scripting. So there's nothing stopping you from having a start_cloak() Lua function that you call with the method Wanderer suggested, with a cloak_ship_name mission variable that you set right before calling the start_cloak function via script-eval(). Basically a roundabout way of passing a function argument.
-C

  

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: fred <-> script interaction
the problem im trying to solve at the moment is how to store cloak textures for multiple ships and still be able to clear them at mission end. so far im just keeping everything in an array tree. in the order of

ships
-ship textures
--the actual texture handels

i figure il just store everything in a single global array. so when i need to clear it il just run a 3 deep nested loop and call unload() on each entry.

another thing i need to fiure out how to do is tell the mission what ships are cloaked. that way the fredder can decide what kind of extra behavior the cloaking should cause, like preventing firing, afterburning, beams, ect. so is there any way to pass a return value from the function to the events system?
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: fred <-> script interaction
There is supposed to be...
Code: [Select]
script-eval-num
    script-eval-num
    Evaluates script to return a numberTakes 1 argument...
    1: Script
script-eval-string
    script-eval-string
    Evaluates script to return a stringTakes 1 argument...
    1: Script
script-eval
    script-eval
    Evaluates scriptTakes at least 1 argument...
    1: Script to evaluate

But IIRC last time i tried the script-eval-num and script-eval-string didnt work... But then again its at least worth a try.
Do not meddle in the affairs of coders for they are soggy and hard to light