Jump to content

[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

      Anyone here played Inscryption? At first, I was like "no, I am not going to play a stupid card game", but this game is so much more than that. It is so meta, full of 4th wall breaks, and feels so damn spooky and weird because of it. Absolutely recommended, if you can stand the visuals. I recommend not reading up too much on it, as that could easily spoil half the incredible surprises. Just know that what you see in the beginning is by far not everything.
      · 4 replies
    • freyk

      Tried to make a tdm advertisement commentpost at one of civvie11 youtube videos about T2. Post got marked as spam. His problem (to not discover TDM for himself),..not my problem.
      But some help of some fellow TDM yt-videocomment posters would be nice. To ask him and others, to play TDM. To get more players/creators. 
      · 4 replies
    • datiswous

      Currently Profile Information has 3 fields, these are shown in forum posts under your avatar:
      1. Gender
      2. Location
      3. Interests
      I think that it could be useful to have an extra field called "Operating system" (under location). It can be useful for tech support and to see what people use.
      Alternatively it could be a more general term, like PC system, so that you can for example state that you use an AMD gpu.
      · 2 replies
    • OrbWeaver

      Greetings fellow kids.
      · 11 replies
    • Crafty_Creeper

      Keep on Creeping on...
       
      · 3 replies
×
×
  • Create New...