Home   Help Search Login Register  

Author Topic: a condition for when a parameter is not set  (Read 1918 times)

0 Members and 1 Guest are viewing this topic.

Offline Surdus Priest

  • Members
  • *
  • Only I can Forgive You!
a condition for when a parameter is not set
« on: 24 Oct 2007, 17:14:37 »

say you have: []exec "blah.sqs"

and in the script i says: _argh = _this select 0

since there is no value to define _argh, not even 0, my question is

what is the condition for when there is nothing in the parameters to define _argh.

basically what does an undefined variable equal? and how would you represent it?
Campaigns are hard, I'll stick with scripting for now!

Offline JasonO

  • OFPEC Patron
  • ****
  • Oh no...
    • The New Life RPG
Re: a condition for when a parameter is not set
« Reply #1 on: 24 Oct 2007, 17:33:00 »
Code: [Select]
_argh = _this select 0
?isnull _argh : _noparams = true

That might do it?

An undefined variable is null I believe.

Offline Surdus Priest

  • Members
  • *
  • Only I can Forgive You!
Re: a condition for when a parameter is not set
« Reply #2 on: 24 Oct 2007, 18:18:09 »
isnull... lol, why didnt i see that one :D
Campaigns are hard, I'll stick with scripting for now!

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: a condition for when a parameter is not set
« Reply #3 on: 24 Oct 2007, 19:11:32 »
isNil

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: a condition for when a parameter is not set
« Reply #4 on: 24 Oct 2007, 19:51:36 »
Baddo is correct, isNil refers to variables, isNull refers to objects, groups, displays and controls.


Planck
I know a little about a lot, and a lot about a little.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: a condition for when a parameter is not set
« Reply #5 on: 24 Oct 2007, 20:27:23 »
Code: [Select]
if (count _this > 0) then
{
   _argh = _this select 0;
}
else
{
   _argh = your desired default value;
};

Offline Surdus Priest

  • Members
  • *
  • Only I can Forgive You!
Re: a condition for when a parameter is not set
« Reply #6 on: 24 Oct 2007, 23:40:33 »
thanks, however it seems that it causes the second parameter o become null.  it was only incase the editor didnt use parameters anyway.




i have another questions however;

my script includes an optional feature where numbers being updated constantly in the hint.
i cant figure out how to set the number of decimal points that appear next to the number.
for example, rather than 34.5004242
i want 34.50

surdus

edit: i also need to know how to modify an added action.  because its no good if the action ID goes up every
time the same action is deleted and replaced.  especially if the mission involves many other important actions that
shouldnt be deleted.
« Last Edit: 25 Oct 2007, 00:37:04 by Surdus Priest »
Campaigns are hard, I'll stick with scripting for now!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: a condition for when a parameter is not set
« Reply #7 on: 25 Oct 2007, 00:45:27 »
Code: [Select]
_value = _value - (_value % 0.01)

Offline Surdus Priest

  • Members
  • *
  • Only I can Forgive You!
Re: a condition for when a parameter is not set
« Reply #8 on: 25 Oct 2007, 02:35:55 »
is there a way of doing that inside the hint format, because i dont want the value to change, i only want it to "appear" as 2 decimal points on the hint.

for example

Code: [Select]
_value = 34.5004242;

hint format ["Answer - %1",_value]

then the decimal change would make the hint say:

Answer - 34.50


i can think of a way to do it the way you said, but that would mean modifying a lot of variables then changing them back.

is there an easier way?

Campaigns are hard, I'll stick with scripting for now!

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re: a condition for when a parameter is not set
« Reply #9 on: 25 Oct 2007, 03:17:30 »
What about to copy the value into another variable and edit this, something like:

Code: [Select]
_showvalue = _value - (_value % 0.01)
hint format ["Answer - %1",_showvalue]
This way the original _value wouldn't be touched.

Myke out

Offline Surdus Priest

  • Members
  • *
  • Only I can Forgive You!
Re: a condition for when a parameter is not set
« Reply #10 on: 25 Oct 2007, 03:47:47 »
that looks good, thanks :D

edit:

is there a way of doing that, but without changing the value?

because that makes teh value appear 0.01 less than what it actually is, so how to i change it to the
real value, but still keep it at 2 decimal points?
« Last Edit: 25 Oct 2007, 17:12:41 by Surdus Priest »
Campaigns are hard, I'll stick with scripting for now!