Good vs. Evil

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
89 so...my dad warned me about the fact that eval() is very slow and thus unless there is a nice function in php like lua's loadString() (together with some nice multi-thread shenanigans ) I really fear the calculations of turns will take too long. I mean look at this:
turn order
The game decides which card goes first
the played card triggers onFirst
battlefield effects trigger onFirst
the played card triggers onCast
battlefield effects trigger onCast
Card does damage/creates effect/heals
The other card gets played
played card triggers onLast
battlefield effects trigger onLast
played card triggers onCast
battlefield effects trigger onCast
Card does damage/creates effect/heals
Cards in each players hand triggers onHold
Battlefield effects trigger onEndTurn
Players discard the chosen cards
Players gain the new cards

battle field effects trigger order
effects owned by the caster
global effects
effects owned by the opponent

that are an awful lot of steps, especially considering a player can have up to 8 local effects and there can be 4 global effects active. Thus worst case scenario there are 20 effects triggering that aren't even from the card itself and each of those need to use eval()

so....yea.....I will do it like this for now but I fear I need to switch tactics sooner rather then later :(
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
95 so...it is apperently possible to add functions to objects at run time, if I combine this with some multi-thread code I can in theory make the strings like "return function(){/*card code here*/};"
This means that when I run eval() I get back the function that runs the card code (in theory) which I then can put inside an object. Then when all the cards are "compiled" and put inside this object I somehow need to give the object to the main-thread.

This all sounds fine and all (except that the code will look very,very dodgy) except for the fact that php apparently doesn't have multi-thread capabilities by itself.
Thus.....I need to find a work around for that.

I hate to say this but if I did this in nodejs it would have been a lot easier (assuming it has a way to execute strings ).

Oh, for those that are wondering why the code would look dodgy, this is how it would look like without evals :p
PHP:
class Foo
{
    public function __call($method, $args)
    {
        if (isset($this->$method)) {
            $func = $this->$method;
            return call_user_func_array($func, $args);
        }
    }
$foo =newFoo();
$foo->bar =function(){ echo "Hello, this function is added at runtime";};
$foo->bar();
}
 

Someone Else 37

Forum Addict
Feb 10, 2013
1,876
1,440
168
97 Lens, it sounds like you have a hack on a hack on a hack. Kinda like how websites that use PHP and MySQL handle database requests.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
98 well, I like to bodge things :p
also, assuming the php extensions I found works for my php version that makes multi threading possible that is one less bodge :p

Another also: its PHP we are talking about, you can do the following with it:
$lolz="test";
$$lolz="awesome;
echo $test;

explanation: I set a variable name using the value of another variable. I think that my "hack" is a lot less worse then doing what I just showed.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
100 and....if I want to get that extension working I would need to recompile php....guess what I am not going to do.......
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
53 and....php decided to make my life a hell once again.
Remember that I decided to create function that edit the stats of cards for use in abilities?
well...let me show you some examples of why I start to dislike that idea as well.
PHP:
//for simplicity sake, lets not write the whole class
public $test="lol";
public function example(){
   function test(){
      echo $this->test; //this will give a crash about $this being used while not in oop context
  }
$that=$this;//to get around the previous crash
function test2() {
    echo $that->test;//this will give an error about $that not being defined
}

function test3() use ($that){//this function won't work at all because it doesn't expect the use
//you expected code in a function that can't even be defined? why?
}
$test3 = function() use ($that) {
echo $that->test;
};//congrats, you now finally where able to find a way to write a function that is able to use a variable from outside its scope without needing to pass it anything or use globals.
//have fun writing the $ thing oh, and don't forget the ; right after the } that is needed if you define functions like this :)
$test3();//$this->test gets echoed like expected 
}
 
Last edited: