Talk:SetGuiParm (script event)
From modwiki
Should it be noted that SetGuiParm refers to setting a variable within the GUI? To me this could easily be confused with gui::gui_parm1 etc. Paveway 20:55, 25 May 2007 (CEST)
Contents |
I'm not sure I'm following you.
I assume you mean how a script like so...
$my_entity.setGuiParm("floor", "District Admin");
... is referencing the variable "gui::floor"?
I suppose they are technically variables but I'd like to think that it's easier to understand if you just think of them as key/value pairs.
First, I can assign an entity with a gui attached to it a key/value pair called "floor" and reference that key/value pair from within a gui with "gui::floor". Secondly, I've never tried addressing any variables with SetGuiParm that didn't have a corresponding key/value pair?
For instance, what if you had a GUI like this...
windowDef Desktop {
rect 0 ,0 ,640 ,480
backcolor 0 ,0 ,0 ,0
visible 1
nocursor 1
float foo 0
How would you assign a value to "Desktop::foo" using SetGuiParm? Does this work? ...
$my_entity.setGuiParm("Desktop::foo", "3");
--Rich 09:16, 27 May 2007 (CEST)
Awkward
The wording just seemed awkward somehow. If you look at SetGuiFloat vs SetGuiParm you might wonder what's the difference, since parm seems to be able to do more... I just thought it should be made clear that in essence SetGuiParm is for setting a "string" of sorts while float is limited to numbers. Again just a minor observation Paveway 06:05, 28 May 2007 (CEST)
I'm at a loss
You're right. It is confusing.
I think both events do the same thing and I'm probably missing some key difference between them. But from what I can tell both events assign a value to what essentially is nothing more than a key/value pair.
And since key/value pairs are strings, it shouldn't matter what the data type is. The result is a string. In that sense, it seems redundant to have a script event for floats and another for strings.
If you ever work out what the difference is, please clue us all in.
--Rich 07:45, 28 May 2007 (CEST)
Difference in the SDK
The two script events are handled in the SDK, more specifically in idEntity. Their code looks pretty similar, as they both set a "variable" directly in all the GUIs an entity has and forces them to update.
( Just for info: this is why setKey doesn't work for GUIs. setKey adds a key to an entity's spawnvalues after the entity was spawned. However, the spawnvalues are only copied to gui variables at spawn time. And it doesn't even copy them all, it only looks for keys starting with "gui_parm" or a key named "gui_noninteractive". Also, setKey does not force an update of the gui, which makes sense. )
On top of that, SetGuiParm may actually do two things: if the key name starts with "gui_", it will also add the given key/value to the parent entity's spawnvalues.
For C++ lovers, here's the code:
void idEntity::Event_SetGuiParm( const char *key, const char *val ) { for ( int i = 0; i < MAX_RENDERENTITY_GUI; i++ ) { if ( renderEntity.gui[ i ] ) { if ( idStr::Icmpn( key, "gui_", 4 ) == 0 ) { spawnArgs.Set( key, val ); } renderEntity.gui[ i ]->SetStateString( key, val ); renderEntity.gui[ i ]->StateChanged( gameLocal.time ); } } } void idEntity::Event_SetGuiFloat( const char *key, float f ) { for ( int i = 0; i < MAX_RENDERENTITY_GUI; i++ ) { if ( renderEntity.gui[ i ] ) { renderEntity.gui[ i ]->SetStateString( key, va( "%f", f ) ); renderEntity.gui[ i ]->StateChanged( gameLocal.time ); } } }
I hope that clears something up.
Do remember though that all GUI parameters are only accessible through "gui::<parameter name>". I highly doubt that the current implementation allows to set "Desktop::floor", for example. That is, until an example proves otherwise. --Kamikazee 12:19, 28 May 2007 (CEST)

