Jump to content
The Dark Mod Forums

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


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 post
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 post
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 post
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 post
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 post
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 post
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 post
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.

×
×
  • Create New...