Jump to content
  • 0

Anyone knows if something similar to PHP's eval ?


Sandbird

Question

Is there an equivalent to php's eval for arma engine ?

Can i set a piece of code to a value and execute it ?

This code would be dynamically created...so its not the same all the time.

And i am not talking about an if statement...The code to be executed can only exist as a value..

 

Something like :

_value = 
{
         if (typeName _x == "STRING") then {
            diag_log _x;
        }
}

[] execVM _value;

?

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

private ["_result","_step","_c"];   
_result = "is false";  
a = {
    _step = "1";  
    true;
};  
b = {  
    _step = "2";  
    false;
};  
_c = {  
    _step = "3";  
    true;
};
scopeName "main";
while {call a && b && _c} do {
    _result = "is true";
    breakTo "main";
};
hintSilent format ["Expression %1, quit at step %2", _result, _step];

Is this what you want? It's called Lazy Evaluation:

http://killzonekid.com/arma-scripting-tutorials-how-to-switch-on-lazy-evaluation/

 

Basicly (bool1 .. {bool2} .. {bool3} .. ...). instead of (bool1 .. bool2 .. bool3 .. ...).

Link to comment
Share on other sites

  • 0
private ["_result","_step","_c"];   
_result = "is false";  
a = {
    _step = "1";  
    true;
};  
b = {  
    _step = "2";  
    false;
};  
_c = {  
    _step = "3";  
    true;
};
scopeName "main";
while {call a && b && _c} do {
    _result = "is true";
    breakTo "main";
};
hintSilent format ["Expression %1, quit at step %2", _result, _step];

Is this what you want? It's called Lazy Evaluation:

http://killzonekid.com/arma-scripting-tutorials-how-to-switch-on-lazy-evaluation/

 

Basicly (bool1 .. {bool2} .. {bool3} .. ...). instead of (bool1 .. bool2 .. bool3 .. ...).

 

 

hmmm i think this will work, thanks

 

Since a can be:

 

a = { _step = "1"; true; };  and i can do " call a"  then it doesnt matter what inside the { }  right ?

Even if whats inside { } in generated dynamically....not by static code i mean..

Could be _step = "1"; true;   or even a whole script...right ?

Link to comment
Share on other sites

  • 0

The above example will output: Expression is false, quit at step 2. So here it is, my lazy evaluation for ArmA tutorial.

 

Well normal if functions would require all values to return true (in arma2) in order to post the message. This one returns all values up intill the false value.

I don't know which bracket you refer to but yes, if you only call on a then b & _c won't matter.

 

private ["_result","_step"];   
_result = "is false";  
a = {
    _step = "1";  
    true;
};  
scopeName "main";
while {call a} do {
    _result = "is true";
    breakTo "main";
};
hintSilent format ["Expression %1, quit at step %2", _result, _step];

This would return "Expression is true, quit at step 1". You can ofcourse change the code around but this is just a basic idea.

It's to make it so that you dont need to do a spiderweb code of if functions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...