Jump to content
The Dark Mod Forums

[solved] Passing variables from GUI to script and vice versa


motorsep
 Share

Recommended Posts

Do you know by chance how to pass values of variables from script to GUI ?

 

 

This GUI I have been working on is for a self-driving vehicle. Player would have to find a fuel cell (power cell) item to place into the vehicle before he can get a ride.

So basically when player trips a trigger entering the vehicle, a script would check for a variable "vehicleIsReady" and if it's 0 (player never placed power cell into vehicle), my GUI would display a red screen saying "out of fuel" and if vehicleIsReady is set to 1, then normal GUI will be displayed (as seen on the video).

How would I do that? Currently I can set variables in GUI code as set "Desktop::variable" "value"; and check if ( "Desktop::variable" == value ) {} but that's for internal to GUI variables/values. I don't know how to pass script variable into GUI using gui_parms, if in some other way.

 

Please help.

Thanks beforehand.

Edited by motorsep
Link to comment
Share on other sites

Do these help:

 

 

    // TODO: load data from an XD file
    // set the number of lines:
    $player1.setGuiInt(gui, "msg_lines", getIntKey("lines"));

    // set the text for the GUI
    $player1.setGuiStringFromKey(gui, "msg_text", self, "text");

    // set number of lines
    $player1.setGuiInt(gui, "msg_lines", getIntKey("lines"));

 

? I'm not sure if "setGUIInt" etc are available in your engine.

"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." -- George Bernard Shaw (1856 - 1950)

 

"Remember: If the game lets you do it, it's not cheating." -- Xarax

Link to comment
Share on other sites

I looked into our _events.script and the only things we got are:


scriptEvent     void setGuiParm( string key, string value );

scriptEvent     void setGuiFloat( string key, float value );

// WTF?!
scriptEvent void        setGui( float guiNum, string gui );
scriptEvent void        precacheGui( string gui );
scriptEvent string      getGuiParm( float guiNum, string key );
scriptEvent float       getGuiParmFloat( float guiNum, string key );
scriptEvent void        guiNamedEvent( float guiNum, string event );

the stuff under // WTF? comment is from D3XP and that had no comments / explanation for it. So I am not sure how to use it.

 

I guess I need to make some tests on small simple gui first :)

Link to comment
Share on other sites

setGUIParm and setGUIFloat should be doing what you want, it sets the key "xyz" to the value "foo" (or 1.0).

 

getGUIParm works the reverse, given the GUI index number (which you get when you create the GUI, it is basically a handle), and a key like "xyz", you get the value back.

 

To see an example, look at tdm_message.gui - it contains references to "gui::mdg_text" (the variable is visible outside the GUI as "msg_text", not sure if "gui::msg_text" would also work). Its value will be transfered to the "text" property of the "message" window on load of the GUI in the onTime 0 block.

 

You could use any other value and manipulate any other value, like foreground color, font etc etc.

Edited by Tels

"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." -- George Bernard Shaw (1856 - 1950)

 

"Remember: If the game lets you do it, it's not cheating." -- Xarax

Link to comment
Share on other sites

Apparently, and I don't know if TDM changed how things work, the only way to pass gui_parms (those are the only variables passable between GUI and script) back to GUI is to have onEven { } code in the GUI ( or onNamedEvent {} ). Do I need to put it into Desktop windowDef or anywhere I please?

 

What is onNamedEvent { } ? How to I define named event ?

Link to comment
Share on other sites

Congratulations on figuring it out.

I wouldn't have known how to do this either, but now that I do it gives me ideas... ;)

What do you see when you turn out the light? I can't tell you but I know that it's mine.

Link to comment
Share on other sites

Well, it didn't work with gui::variable. I had to use gui::gui_parm1 (2, 3, etc.) to toss around strings/floats. Also GUI won't accept input from the script without onEvent or onNamedEvent. The latter is preferable, as onEven runs every frame and also registers mouse leaving/re-entering GUI (Desktop). So refocusing on GUI will trigger whatever you have in the onEvent {} block. So I think onNamedEvent is what should be used all the time, except for cases when focusing on GUI should trigger something.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recent Status Updates

    • STiFU

      I started skateboarding again after a 20 year hiatus. Whish me luck I don't break anything. 😄
      · 1 reply
    • freyk

      Some years earlier i created some launchers for TDM. uploaded today some new sourcecode and executables on my github repo.
       
      · 0 replies
    • Epifire

      Say, I know it's been a while since the site got overhauled from the crash. But did we ever figure out if/how to get the recent topics & replies list back? It's not a total deal breaker but it was nice for becoming a thread creeper again...


      · 2 replies
    • Epifire

      Some of you who've been on the TDM discord know I was out of work last Winter, just putting in hrs for the developer portfolio. Currently I've been working a seasonal job to pay the bills and now I'm finally in my last week before I get bumped off. Things will be tight but I'm planning a long off period to make as much content as I can. Big plans in Unreal Engine as well as my most ambitious TDM collab yet! Never been so excited to be a stuck at home to pursue my life's work. With a lotta time and maybe some luck, I'm hoping to get enough art work done that I may start applying around to studios.
      · 4 replies
    • STiFU

      I finally got around to play Prey and I truly loved it. It is an incredible homage to System Shock and Deus Ex. While the gameplay is not en par with those two titles, the game makes up for that with its well written lore and story. The whole "world" just feells so authentic and it features a ton of really god environmental story-telling. Recommended for every immersive sim fan, i.e., everyone on this forum.
      · 5 replies
×
×
  • Create New...