Changing "float variable" to "0.0" would get rid of this message.

AlbinoRhino

Active member
I am puzzled. I recently added some code to a script. I define some variables...

Code:
float ecold = 0.0;
float ehot = 0.0;
float espooky = 0.0;
float estench = 0.0;
float esleaze = 0.0;

...and then a little later in the script, after it is possible that those values have changed, I have this bit of code...


Code:
foreach key in $floats[estench,esleaze,ecold,ehot,espooky]
{
     if ( key > 0.0 ) key = .50;
}


...and that bit causes Mafia to give me these messages, the first time the script runs after I have made a change to it...


Changing "estench" to "0.0" would get rid of this message. (rhinolib.ash, line 564)
Changing "esleaze" to "0.0" would get rid of this message. (rhinolib.ash, line 564)
Changing "ecold" to "0.0" would get rid of this message. (rhinolib.ash, line 564)
Changing "ehot" to "0.0" would get rid of this message. (rhinolib.ash, line 564)
Changing "espooky" to "0.0" would get rid of this message. (rhinolib.ash, line 564)

How do I get rid of those messages without losing my variable names ?
 

Veracity

Developer
Staff member
Code:
$floats[estench,esleaze,ecold,ehot,espooky]
You can't do that. $floats gives you a "plural constant". The items within the [] must be "constants" of type "float".

"estench" is not a "constant" of type "float". It is the name of a variable of type "float".

You're going to have to deal with the variables individually. Something like:

Code:
if ( estench > 0.0 ) estench = .50;
... etc ...
Alternatively, you could do this:

Code:
float[element] values;

foreach el, val in values
{
    if ( val > 1.0 ) values[el] = .50;
}
Name the map something meaningful than "values", of course.
 

heeheehee

Developer
Staff member
Mutating "key" probably doesn't do what you want it to do.

Out of curiosity, I tried "foreach key in {ecold, ehot, espooky, estench, esleaze} { ... }". Unsurprisingly, it didn't work (and if it did, it probably wouldn't be useful).

"float[5] map{ecold, ehot, espooky, estench, esleaze};" worked just fine, though.
 

AlbinoRhino

Active member
That makes sense. Thank you much for the reply. ( I discovered the "deal with them individually" solution but I still didn't grok why it was like that. )
 

heeheehee

Developer
Staff member
Although, again, mutating key wouldn't be what you wanted -- the corresponding variables wouldn't be modified as you might expect. Veracity's suggestion of using a proper element -> float map would probably be what you want.
 
Top