Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #19  
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
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:13 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.