Jump to content
The Dark Mod Forums

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


motorsep

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.

  • Recent Status Updates

    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 6 replies
    • Ansome

      Turns out my 15th anniversary mission idea has already been done once or twice before! I've been beaten to the punch once again, but I suppose that's to be expected when there's over 170 FMs out there, eh? I'm not complaining though, I love learning new tricks and taking inspiration from past FMs. Best of luck on your own fan missions!
      · 4 replies
    • The Black Arrow

      I wanna play Doom 3, but fhDoom has much better features than dhewm3, yet fhDoom is old, outdated and probably not supported. Damn!
      Makes me think that TDM engine for Doom 3 itself would actually be perfect.
      · 6 replies
    • Petike the Taffer

      Maybe a bit of advice ? In the FM series I'm preparing, the two main characters have the given names Toby and Agnes (it's the protagonist and deuteragonist, respectively), I've been toying with the idea of giving them family names as well, since many of the FM series have named protagonists who have surnames. Toby's from a family who were usually farriers, though he eventually wound up working as a cobbler (this serves as a daylight "front" for his night time thieving). Would it make sense if the man's popularly accepted family name was Farrier ? It's an existing, though less common English surname, and it directly refers to the profession practiced by his relatives. Your suggestions ?
      · 9 replies
    • nbohr1more

      Looks like the "Reverse April Fools" releases were too well hidden. Darkfate still hasn't acknowledge all the new releases. Did you play any of the new April Fools missions?
      · 5 replies
×
×
  • Create New...