View Single Post
  #6  
Old 05-07-2011, 04:47 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Devil_Lord2 View Post
I don't get it...
You should think in terms of expressions. When a script runs, it evaluates/reduces expressions.




Let's start with some hypothetical weapon script:
PHP Code:
function test(temp.x) {
  return 
temp.x+2;
}

function 
onWeaponFired() {
  
temp.this.test(10);
  echo(
temp.x);


And now, say this weapon is fired. This means we will be running the code:
PHP Code:
  temp.this.test(10);
  echo(
temp.x); 
Let's see what happens...

Step 1
On the first line, we need to call the test function with the value 10. When a function is run, we can replace the spot it was called at with the value it returns.

So, after test runs, this is what we have:
PHP Code:
  temp.12;
  echo(
temp.x); 
Step 2
And of course, this step is fairly simple...

So we get:
PHP Code:
  echo(12); 
Step 3
That code will be executed and will display 12 in the F2 console.



This method of evaluating scripts by hand can be very useful when trying to understand how one works (though it's normally done in your head).
Reply With Quote