News:

One Minute Game Review by The Happy Friar: https://ugetube.com/@OneMinteGameReviews
Also on Rumble: https://rumble.com/c/c-1115371

idTech 4 (aka Doom 3 tech) Discord Server! https://discord.gg/9wtCGHa

Main Menu

Getting var values from GUis?

Started by argoon, September 28, 2017, 04:07:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

argoon

Hello guys i know that i can set a variable value in a GUI from the engine code using for example somegui->SetStateInt("varName"); and it works fine, but i can't seem to do the inverse, get a value from a gui variable to the game code, i tried using the somegui->GetStateInt("varName"); but it returns zero every time, no matter to what value i set the GUI variable.

what i'm trying to do is create a grid based inventory system, and when i click in a "slot" i tell the c++ code what slot i interacted with.

Phrozo

If you can't get the value how do you know you are actually setting it? Neither get or set state functions will inform you if are trying to read or write to a variable that can't be found or doesn't exist. Are you sure your variable can be found?

bitterman

AFAIK this works like entity -> somegui -> parm. Then parm is for entity, not for gui itself (not sure about pda gui, perhaps the player is that entity).


argoon

#3
Quote from: Phrozo on September 28, 2017, 11:14:31 PM
If you can't get the value how do you know you are actually setting it? Neither get or set state functions will inform you if are trying to read or write to a variable that can't be found or doesn't exist. Are you sure your variable can be found?

Hello Phrozo thanks for the reply,  I'm really not sure of anything, I'm still learning this stuff, because gui scripting tutorials are so scarse, I'm learning by trial and error, the only thing I'm sure of, is that when inspecting the gui in the visual studio watch window, I see that at lest the variable name I wrote in the gui desktop is there.

In the case of set, at lest for variables using "gui::varname" I know I'm setting the values from the c++ side  because they work, for other vars I never really tried, I've used namedEvents for the most part,  never tried to "get" a variable value back from the gui.

I also see that Id almost never used GetStateInt or others like it, so perhaps I'm just not thinking this in the right way, but for now I can't see how I could make what I'm trying to make without retrieving a var value from the gui.

Tell me, what would you do, if you add a inventory system where you have a grid based look and you assign different items to each slot (this part already works fine),  the "grid" in the c++ side is just a array of structs, with info like, slot ID, what item is in what slot, a icon path, a item counter per slot, etc, ( I use namedEvents and gui::varname,  to assign the right info to the right "slot"  in the gui file), but then you wanted to have the ability to click in a particular slot (onAction) and have that affect the right array index in the c++ side?

I know I can use set "some cmd name", by using the "handle single gui cmds" function from the player.cpp, like id did but for that, I think I need to do different cmd's to every item in the inventory, if they happen to be in different slots, for example, if I wanted to remove a key from slot 1 in the inventory,  I would need to do,  a remove key1 function,  do another function to remove key2 from slot 2, etc, instead of the a single -  set "removeItem"  function and have that remove the right item from the right gui slot and the right array index. Why I think so?  Because afaik there's no way to tell the c++ code in what window a particular onAction was triggered without using variables ?

Again I may be thinking all this wrong (most likely) and there's a simple way to do that I'm just ignorant about.

Quote from: bitterman on September 29, 2017, 03:22:09 AM
AFAIK this works like entity -> somegui -> parm. Then parm is for entity, not for gui itself (not sure about pda gui, perhaps the player is that entity).

That is right and for the pda gui the player is indeed the entity, the pda gui is called from the player def file, still don't know how this can help me, do I need to define the var with gui::varname for "get" like I do for set ? Not near my pc so can't test.

bitterman

#4
Well, we can easy get/set entity's keys.
Is it necessary to store info about ltem location in gui parm?

argoon

Quote from: bitterman on September 29, 2017, 05:28:14 AM
Well, we can easy get/set entity's keys.
Is it necessary to store info about ltem location in gui parm?

You are certainly right but I want to do this for performance reasons, reading strings from the entities def file and convert them to float for example,  is very performance heavy,  even id recommended not doing that to much, and I will have plenty of information on my inventory to be reading it all from the player def file, but if I have no choice then I will do that.

bitterman

It's just an idea, but if it possible to encode item's location in one string (comparing with coords of the grid window)  then theoretically it possible to get/set it via "inv_id" which is a native part of inventory system.

argoon

Is official i'm dumb, it was right there in front of my face and i just didn't see it, to "get" values from gui's is just how to "set" values from gui's... just use - set "gui::varname" "value".  :-[

After doing that i was able to retrieve the value.

So this means all other vars in a gui file that don't use the gui::varname system are only visible in the gui scope. I mean they seem to be invisible to anyone outside the GUI file.

   

bitterman

I tought about your inventory mod and how to realize it.

Can you describe the main algorithm?

Let say:

1. Allocate window in pda.
2. Draw grid, split to units (cells).
3. Fill cells with items indexes based on some items inv. parms.
4. If receive onAction from window then convert mouse coords to cells.
5. Read index (item id) from target cell.
6. Do action.

Something like this?

argoon

Quote from: bitterman on September 30, 2017, 02:49:57 AM
I tought about your inventory mod and how to realize it.

Can you describe the main algorithm?

Let say:

1. Allocate window in pda.
2. Draw grid, split to units (cells).
3. Fill cells with items indexes based on some items inv. parms.
4. If receive onAction from window then convert mouse coords to cells.
5. Read index (item id) from target cell.
6. Do action.

Something like this?

First i must say i'm not using the Doom 3 pad gui script at all, mine is totally new, but is more or less that, I don't convert mouse coords to the cells location tho, I just set a "gui::Slot_id" var to a number corresponding to the array index that i know a priory that gui slot belongs to, in that way i can go directly to the array index instead of doing a search, I don't know if this is a good way to do it but it works. :)

djamelo

AFAIK this works like entity   -> somegui -> parm. Then parm is for entity, not for gui itself (not sure about pda gui, perhaps  the player is that entity).