Author Topic: The new Lua SEXP interface  (Read 6357 times)

0 Members and 1 Guest are viewing this topic.

Offline Bryan See

  • Has anyone really been far as decided to use even go want to do look more like?
  • 210
  • Trying to redeem, but under Tiger Parents
    • Skype
    • Steam
    • Twitter
Re: The new Lua SEXP interface
Excuse me, guys.

What about the ability to override existing SEXPs?

For example, I want to augment the cutscene SEXPs so that camera movements will be reminiscent to recent movies and games - thus improving cinematic experience of in-mission cutscenes.
Bryan See - My FreeSpace Wiki User Page (Talk, Contributions)

Full Projects:
Shattered Stars

Campaigns:
Lost in the Mist - Cyrene vs. Psamtik
FreeSpace: Reunited

Ships:
GTS Hygeia, GTT Argo, SC Raguel

Tools:
FSO TC/Game template

I've been under attack by Tiger Parents like Jennifer Pan...

 

Offline m!m

  • 211
Re: The new Lua SEXP interface
Existing SEXPs will always override SEXPs added by this new system. You cannot replace a built-in SEXP with a Lua SEXP since that could cause a lot of problems.

 

Offline Bryan See

  • Has anyone really been far as decided to use even go want to do look more like?
  • 210
  • Trying to redeem, but under Tiger Parents
    • Skype
    • Steam
    • Twitter
Re: The new Lua SEXP interface
That means if I want to override them without actually replacing built-in SEXPs with Lua SEXPs, I just have to create them to complement them.
Bryan See - My FreeSpace Wiki User Page (Talk, Contributions)

Full Projects:
Shattered Stars

Campaigns:
Lost in the Mist - Cyrene vs. Psamtik
FreeSpace: Reunited

Ships:
GTS Hygeia, GTT Argo, SC Raguel

Tools:
FSO TC/Game template

I've been under attack by Tiger Parents like Jennifer Pan...

 

Offline m!m

  • 211
Re: The new Lua SEXP interface
If you mean by that that you need to create a new SEXP with a different name and then use that in your missions then yes, that's how you need to do it.

 

Offline Bryan See

  • Has anyone really been far as decided to use even go want to do look more like?
  • 210
  • Trying to redeem, but under Tiger Parents
    • Skype
    • Steam
    • Twitter
Re: The new Lua SEXP interface
I got it.

Can these SEXPS may include built-in SEXPs as well as some Lua code?
Bryan See - My FreeSpace Wiki User Page (Talk, Contributions)

Full Projects:
Shattered Stars

Campaigns:
Lost in the Mist - Cyrene vs. Psamtik
FreeSpace: Reunited

Ships:
GTS Hygeia, GTT Argo, SC Raguel

Tools:
FSO TC/Game template

I've been under attack by Tiger Parents like Jennifer Pan...

 
Re: The new Lua SEXP interface
mn.evaluateSEXP springs to mind.

 

Offline m!m

  • 211
Re: The new Lua SEXP interface
This feature has been merged into the master branch and the newest nightly already contains the new code. I added documentation for how this works to the wiki: http://wiki.hard-light.net/index.php/Dynamic_SEXPs

 

Offline Axem

  • 211
Re: The new Lua SEXP interface
Quote
ship
This parameter is the name of a ship. The script will receive this value as a string which is the ship name. mn.Ships can be used for getting a ship handle from the name. The name may be invalid if the ship does not exist or is no longer present in the mission.
...
team
This parameter is a handle to a specific team. The script will receive this value as a team handle.
waypointpath
This parameter is a reference to a specific waypoint path. The script will receive this as a waypointlist handle.
variable
This is a reference to a SEXP variable. This is a reference to the actual variable and not its contents. The script will receive this as a sexpvariable handle.

Is there a reason Ship gets passed as a string, but everything else is passed as their handle?

 

Offline m!m

  • 211
Re: The new Lua SEXP interface
Quote
The name may be invalid if the ship does not exist or is no longer present in the mission.
That is the reason :p

Ships are (so far) the only parameter type that can be invalid when the SEXP function is called. All other types will always be valid which means that they can be converted to their Lua handles without worrying about producing an invalid handle. Also, when the script receives the ship name as a string it can do more with an invalid name than with an invalid handle. The name can at least be used for displaying a helpful message which includes the ship name. If the script only received the invalid ship handle then all it could do would be to determine that the handle is invalid and nothing more since the invalid ship handle only has that one bit of useful information.

I hope that clears up my reason for passing this as a string.

EDIT: I changed the description of the ship type a bit to explain why it is a string.

 

Offline Axem

  • 211
Re: The new Lua SEXP interface
Hmmm, okay. Buuuttt...

Through use of arguments/variables and unfortunate typos/cross mod files without paying attention, one could throw an invalid handle for teams or waypoint paths.

And also the standard sexp behavior for being given an invalid ship reference is just to silently fail. "self-destruct a ship that's departed? It couldn't be helped." The scripter has the power with :isValid() to check ship object validity and if it can't work they should either output a debug print saying "this function couldn't work" or just silently fail.

Now I super agree that it would be great to be able to know which object failed so it can be narrowed down a lot faster, but I also think things should be consistent. Intuitive behavior is more important I think than syntactical sugar. Either method is fine by me, just as long as its the same for every parameter. Just my two cents anyway!

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: The new Lua SEXP interface
Intuitive behavior is more important I think than syntactical sugar.
Seconded. If being able to know the name of the object is so useful in one case, it might be useful in all cases.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline m!m

  • 211
Re: The new Lua SEXP interface
Well, ok then. I though it would be better to have more information in case of an invalid ship name but I don't really have a preference here so I will just change it to a ship handle.

EDIT: I made the changes. PR: https://github.com/scp-fs2open/fs2open.github.com/pull/1539
« Last Edit: December 22, 2017, 02:28:28 am by m!m »

 
Re: The new Lua SEXP interface
I read that more as "why not pass everything though strings, cos someone's going to mistakenly refer to Gramma wing sometime".

 

Offline m!m

  • 211
Re: The new Lua SEXP interface
In case people look here for documentation, I made a wiki article about how to use this new system: http://wiki.hard-light.net/index.php/Dynamic_SEXPs

EDIT: Oops, I though I hadn't posted that link here yet. Well, it's better to have it twice I guess :nervous:

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: The new Lua SEXP interface
For the naming section, you might want to strongly recommend prefixing the names of SEXPs with lua- so that there is no chance of a SEXP being added later by a coder which has the same name. The example you use of cloak-disable is a good example of something which could later be added by a coder and if the lua version has different parameters to the script one it would break all the missions using the scripted version.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 
Re: The new Lua SEXP interface
There seems to be a mismatch between the documentation and the Lua example:

Quote
ship
This parameter is the name of a ship. The script will receive this value as a ship handle. If the name provided by the mission is invalid (if the ship has not arrived yet or if it is not present anymore) then the script will receive an invalid ship handle.
[...]
variable
This is a reference to a SEXP variable. This is a reference to the actual variable and not its contents. The script will receive this as a sexpvariable handle.

But, the Lua snippet looks up the ship/variable by name:

Code: [Select]
ba.print(mn.Ships[arg2].Name)
ba.print(tostring(mn.SEXPVariables[arg3].Value))

It seems like one of these sections needs to be corrected to make them line up.

  

Offline m!m

  • 211
Re: The new Lua SEXP interface
I forgot to fix that when the changes were merged. I don't know how the SEXP variable lookup even got in there. That was never necessary but I fixed that as well...