Author Topic: SEXP Containers - Now in Beta!  (Read 9899 times)

0 Members and 1 Guest are viewing this topic.

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
SEXP Containers - Now in Beta!
Okay, I'm going to call this feature in Beta now. Although I'm likely to add features, what is already there probably isn't going to change much so FREDDERS can feel pretty confident that I'm not going to pull the rug out from under them.

What is this?

For those who didn't read the previous thread, what you've got here is an implementation of two standard C++ features (deques and hash maps). Think of these as variables on steroids in terms of what they can do and how much power they have.

A deque is a double ended queue. That means you basically can make a list of ships, messages, subsystems or any other string or number you wish and then tell FRED "Give me the first / last thing from the list." Basically it's similar to the argument lists you can use with when-argument except that they exist independently of the event and thus can be used in several events at the same time (With an argument list you'd have to copy it to every single event).

A map allows you to specify pairs of variables. The key and the value. That means if you specify Alpha 1 as the key you can simply ask the game to retrieve whatever value you've associated with it (a message, another ship, whatever you want). You could then add Beta 1, 2, 3 etc and have them have different values.

Both containers support multidimentionality, that means you can have a map or deque with each entry being another container.

Although there is still quite a lot to do I'm basically I'm putting this up so that FREDders can play with it and help me find bugs / ask for features. As always, these are more likely to get attention while I still remember code than weeks or months later when I'll have to relearn how it all works. I'll be writing a tutorial on how to do cool stuff with this feature at some point but I wanted to make this available to play with as it's almost certain to still have some bugs due to the way it required quite a large edit of sexp_tree.cpp (It should be a lot more stable in FS2_Open than FRED though).


Since the feature is still in beta the modify container dialogue hasn't been implemented yet (I plan to work on it next!). You can add containers with the Add Container option but if you want to edit them you'll have to do it via notepad (or use the add-to-list / add-to-map SEXPs). Pretty much everything else should work though. I've tried to implement everything so that it looks similar to the way FRED handles variables so that it feels familiar. There are a couple of things that might need some explanation though.

If you have this SEXP

Code: [Select]
when
- true
- self-destruct
-- Ship_List
--- Get First


The game will go into the Ship_List container, get the first ship in the queue and give that to the self-destruct SEXP. If you have this though


Code: [Select]
when
- true
- self-destruct
-- Ship_List
--- Get First
--- Get Last


The game will assume that the first entry in Ship_List is another list and the last entry in that second list is the actual name of the ship. So in order to use multidimentionality you must use Add Data from the menu to add an extra Get First and you must have an entry in the Ship_List which is the name of a list with '&' before and after the name of the container (e.g &Another_Ship_List&).


The other issue people might encounter is when using the new SEXPs that expect the name of a container.

Code: [Select]
when
- is-container-empty
-- Ship_List

If you have this event and you right click on Ship_List you will notice that both the Replace Container and Replace Data options are available. They are not the same! Replace Data is the one you probably want. If you use the Replace Container option the game will assume you mean the contents of the container (i.e you don't want to check if Ship_List is empty, but rather that Ship_List is a multidimentional container and that it contains the name of a second container you want to check). You can tell what the game is thinking because if you use Replace Container it will add a modifier and will instead look like this.

Code: [Select]
when
- is-container-empty
-- Ship_List
--- Get First



Anyway, here's the build for you FREDders to play with. I can't post the code in here as it actually breaks the forum limit. I'll add it as an attachment though.

If you have any questions, please ask. I really want this feature to get some heavy testing now. Report any bugs you find on this thread or on IRC (if I'm online).

Future features :-
I want to be able to output containers to messages the same way you can use $variable_name in a message to output the value of the variable. Of course, this is likely to be more complicated than with a variable since I'll need to code to pick which entry in the container to output. - Done
Containers need to be tied into the event log. At the moment they don't output anything. - Done
I plan to add persistence to containers in the same way that you can have persistent variables.
I'll be adding more SEXPs to allow you to interact with containers. For instance one SEXP I'll add soon is the ability to output all the keys from a map into a list. - Done
I'll also be adding multiplayer support at some point.

[attachment kidnapped by pirates]

[attachment deleted by nobody]
« Last Edit: May 22, 2015, 09:24:43 am by karajorma »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline pecenipicek

  • Roast Chicken
  • 211
  • Powered by copious amounts of coffee and nicotine
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • PeceniPicek's own deviantart page
Re: SEXP Containers - Now in Beta!
So, in effect, you just implemented PHP's particular flavor of "arrays" into FSO :p


 :yes2: in any case :D
Skype: vrganjko
Ho, ho, ho, to the bottle I go
to heal my heart and drown my woe!
Rain may fall and wind may blow,
and many miles be still to go,
but under a tall tree I will lie!

The Apocalypse Project needs YOU! - recruiting info thread.

 

Offline Colonol Dekker

  • HLP is my mistress
  • 213
  • Aken Tigh Dekker- you've probably heard me
    • My old squad sub-domain
Re: SEXP Containers - Now in Beta!
It made my head hurt but I know that is because coding stuff is my bane.

Campaigns I've added my distinctiveness to-
- Blue Planet: Battle Captains
-Battle of Neptune
-Between the Ashes 2
-Blue planet: Age of Aquarius
-FOTG?
-Inferno R1
-Ribos: The aftermath / -Retreat from Deneb
-Sol: A History
-TBP EACW teaser
-Earth Brakiri war
-TBP Fortune Hunters (I think?)
-TBP Relic
-Trancsend (Possibly?)
-Uncharted Territory
-Vassagos Dirge
-War Machine
(Others lost to the mists of time and no discernible audit trail)

Your friendly Orestes tactical controller.

Secret bomb God.
That one time I got permabanned and got to read who was being bitxhy about me :p....
GO GO DEKKER RANGERSSSS!!!!!!!!!!!!!!!!!
President of the Scooby Doo Model Appreciation Society
The only good Zod is a dead Zod
NEWGROUNDS COMEDY GOLD, UPDATED DAILY
http://badges.steamprofile.com/profile/default/steam/76561198011784807.png

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: SEXP Containers - Now in Beta!
Maps aren't really much more complicated than variables really. In reality all a map is, is a collection of SEXP variables in one package. The advantage is that you can do something like this

when-argument
- Any-of
-- Alpha 2
-- Alpha 3
-- Alpha 4
- <
-- distance
--- Argument
--- SC Sathanas
-- 4000
- Send-Message
-- Argument
-- High
-- Ship_Map
--- Argument

That allows you to have each ship send a different message. You would just make a map and assign each ship a different message
Code: [Select]
Alpha 2 - Alpha 2 Message
Alpha 3 - Alpha 3 Message
Alpha 4 - Alpha 4 Message

I'm sure that's a problem many FREDders have seen before.

« Last Edit: October 30, 2014, 02:26:48 am by karajorma »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: SEXP Containers - Now in Beta!
Thanks to MageKing for testing. Two bugs have now been fixed. I've noticed that using the At modifier is borked though. I'll fix that in a bit. 

EDIT : It should work now. New builds uploaded. Linked in the top post.
« Last Edit: October 30, 2014, 11:17:15 am by karajorma »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: SEXP Containers - Now in Beta!
So I wanted to make a quick test to make sure things were working, so I created a list and a map defined thusly:
Code: [Select]
$Lists
$Name: Ship_List
$Data Type: String
$Data: ( "Alpha 2" "Alpha 3" "Alpha 4" )

$End Lists

$Maps
$Name: Message_Map
$Data Type: String
$Data: ( "Alpha 3" "Alpha 3 Says Something" "Alpha 4" "Alpha 4 Says Something" "Alpha 2" "Alpha 2 Says Something" )

$End Maps
I then created this (I thought) simple event to go with them:
Code: [Select]
$Formula: ( when
   ( and
      ( not
         ( is-container-empty "Ship_List" )
      )
      ( >
         ( mission-time )
         @Message_Timer[5]
      )
   )
   ( send-message
      &Ship_List& ( "Get_First" )
      "High"
      &Message_Map& ( &Ship_List& ( "Remove_First" ) )
   )
   ( modify-variable
      @Message_Timer[5]
      ( + @Message_Timer[5] 5 )
   )
)
+Name: Send Contained Messages
+Repeat Count: -1
+Trigger Count: 3
+Interval: 1
Upon actually testing this mission, I get Alpha 4 sending a message (at the expected time), and nobody else, no matter how long I wait.
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 karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: SEXP Containers - Now in Beta!
Fixed it. The problem is that there are calls to CTEXT in the mission loading code.

I wrapped the call to actually remove entries from the container in a "if (Game_mode & GM_IN_MISSION) " and it worked perfectly after that.

I'll upload new builds in a couple of hours once I'm not on my phone.

EDIT: New build uploaded.
« Last Edit: October 30, 2014, 11:43:56 pm by karajorma »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: SEXP Containers - Now in Beta!
Build and patch updated.

- Added the new get-map-keys SEXP which will output all the keys from a map into a list.
- Added support for using containers in messages, briefings, debriefings, etc. You need to write the container name in this format &Container_Name&Key_Name& for maps.
For lists use &Container_Name&Modifier& where modifier is one of the list modifiers such as Get_First or Remove_Last. If you want to use the At modifier you must also add an index. Remember that indexes are 0th order so &Container_Name&At1& will supply the 2nd entry in the list you need a 0 not a 1 for the first entry.
- Added preliminary support to output to the event.log whenever a container is used. Same as for variable or arguments.
- Various bug fixes from the thread, IRC or which I found myself.

I've decided I'm going to dump or alter large sections of the current code for the Add Container menu option. I was for the most part copying how the SEXP variable code does it, but the further in I got, the more I realised how deeply limited and stupid the current variable dialogs are (I can only edit or delete one variable at a time? Seriously?). I should at least try to write something better than that. Both Add Container and Modify Container can hopefully be rolled into a single dialog that can add, modify and delete containers as the FREDder wishes. But since I've already given FREDders the Add Container dialog and you can modify containers fairly easily in notepad, it's not a huge priority compared with other things I'd like to see.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: SEXP Containers - Now in Beta!
- Added support for using containers in messages, briefings, debriefings, etc. You need to write the container name in this format &Container_Name&Key_Name& for maps.
For lists use &Container_Name&Modifier& where modifier is one of the list modifiers such as Get_First or Remove_Last. If you want to use the At modifier you must also add an index. Remember that indexes are 0th order so &Container_Name&At1& will supply the 2nd entry in the list you need a 0 not a 1 for the first entry.
Is there support for lists of lists with this syntax? Can you say &Container_Name&Get_First&Get_First& or something?
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 karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: SEXP Containers - Now in Beta!
Not for that one yet. I may add that later though.

EDIT: Added support for multidimentional containers in messages. I'll update the code + builds later though got other things to work on for now.
« Last Edit: November 05, 2014, 07:39:29 am by karajorma »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: SEXP Containers - Now in Beta!
:bump:

Looks like it's been a while since I updated this thread. New builds and patch file attached.

The old Add Container, Modify Container, Replace Container paradigm which I copied from variables has been consigned to the dustbin of history. Instead you have an Edit Containers option which allows you to add and edit them (and eventually remove them once I get around to adding a button for that!) and the standard Replace Container to change data into a container. Various other bugs have been fixed too.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: SEXP Containers - Now in Beta!
Deleting containers should now work too!
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline Rheyah

  • 28
  • Will release something one day. Promise.
Re: SEXP Containers - Now in Beta!
Hiya,

How recent is the build you used?  I'm looking at using this for a particular event (involving a series of randomised locations which the player must visit in a particular order) but I also have flags which were implemented during January, I think.  Is there any way a more recent build could be used?

I am not familiar with the patching process.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: SEXP Containers - Now in Beta!
I'll try to get an up to date build up by the end of the day. I had some computer issues and haven't reinstalled MSVC or SVN yet. Once I have those it should be pretty easy to build for you.

EDIT : New version based on SVN checked out today available here.
« Last Edit: March 25, 2015, 04:45:18 am by karajorma »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 
Re: SEXP Containers - Now in Beta!
kara, correct me if I'm wrong here, but based on your description in the first post, deqs and maps are arrays, and an array is, as you desribed these items, a variable on steroids. Not only should you be able to get the first or last item, it ought to also be possible to get a specific range of items, or to iterate though the array, at least in theory. In practice it would depend on the implementation, obviously.
There are only 10 kinds of people in the world;
those who understand binary and those who don't.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: SEXP Containers - Now in Beta!
Deques are basically similar to an array but maps are unordered. With a map getting the first object out of the map is going to give you a random object since there is no way to be certain which item will be first. Even when running the same mission again you can't be certain that the map will contain objects in the same order.

Theoretically it is possible to iterate through the entire array via a command similar to Get First, etc. However in practice it proved to be quite hard to implement so I left it up to the FREDder to do it. It is definitely possible to write a SEXP that will iterate through the array.
« Last Edit: April 16, 2015, 08:02:06 pm by karajorma »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 
Re: SEXP Containers - Now in Beta!
Ah. I missed that maps are unordered. Cool. I didn't even know you could do that. But deqs are definitely a sort of array. Which means that you should not only be able to get first or last, but any item you have the index of, at least in theory. In practice, I have no idea if the system is set up that way.
There are only 10 kinds of people in the world;
those who understand binary and those who don't.

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: SEXP Containers - Now in Beta!
Ah. I missed that maps are unordered. Cool. I didn't even know you could do that. But deqs are definitely a sort of array. Which means that you should not only be able to get first or last, but any item you have the index of, at least in theory. In practice, I have no idea if the system is set up that way.
There's an "At" modifier for retrieving the entry at a specific index of a list container.
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 karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: SEXP Containers - Now in Beta!
While we're on the subject, does anyone have the patch file I attached earlier? The most recent version I have is on my broken computer and I don't fancy having to take it apart, sticking the drive in an enclosure and then putting it all back together again when I am able to get the PC fixed.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 
Re: SEXP Containers - Now in Beta!
This file?

[attachment deleted by nobody]