Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
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
  #2  
Old 05-07-2011, 05:07 AM
Devil_Lord2 Devil_Lord2 is offline
David K?
Devil_Lord2's Avatar
Join Date: Apr 2011
Location: PA, MD.
Posts: 643
Devil_Lord2 can only hope to improve
Quote:
Originally Posted by WhiteDragon View Post
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);

I get up to here so far, excluding why this. is in front of a function... probably because I've never seen it before.. I would understand it without this. in front. Can it use that?

I thought

whatever = 6
return whatever

just returns 6 in whatever to the function that called it.. if it were a number, array, string, variable, or float, it would be inside whatever.. in this case 6..

-WILL EDIT-
Still trying to figure out the geometry/radians type post.. I haven't seen or used it at all.. If I read it a few times I might understand it :x


Okay, at first I wasn't reading "Degree to Radius" but I get it now..
I've taken Trig, Geometry, and Algebra 2 ... Can't say I remember any of it, and stating something math-wise confused the hell out of me and I was missing the point of the function lol

Yeah I get it now.. I love math, but it isn't my strong suit..
I got out of Computer Science because of my C Programming class..
My friend would find the scripts on the internet, and I'd change them towards what we needed... the final we had a third person trying to help and I missed a few classes and didn't understand it at all.. I passed but it wasn't enough for me to feel like I knew what I was doing really >.>

I'm more into art, but I'd still like to be able to know this.. seems easier to learn with the community here.

But yes I get you both.. I've always seen return ??? but never how it was used lol..
Thank you both!
__________________

Digital Media Artist - David K? </3 (UnLoved)
www.davidkrout.com
www.twitch.com/DavidKkz



Reply With Quote
  #3  
Old 05-07-2011, 05:29 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 get up to here so far, excluding why this. is in front of a function... probably because I've never seen it before.. I would understand it without this. in front. Can it use that?
This this is slightly confusing to explain without a core understanding of how code evaluates. If you were to not write it, it would just be there implicitly, and sneak around in the background until it jumps out and confuses you. It's definitely important to learn about this (and the related concept of "objects") before you start seriously coding though.


Quote:
Originally Posted by Devil_Lord2 View Post
I thought

whatever = 6
return whatever

just returns 6 in whatever to the function that called it.. if it were a number, array, string, variable, or float, it would be inside whatever.. in this case 6..
It's best to throw away this idea rather than try to patch it up to something correct. It's somewhat close, but far away enough that'd it be faster to ignore it.


Quote:
Originally Posted by Devil_Lord2 View Post
Still trying to figure out the geometry/radians type post.. I haven't seen or used it at all.. If I read it a few times I might understand it :x
He was just giving examples rather than an explanation of how to think about each example. Look at Chris's post to try and learn by observation. Look at mine if you want a walkthrough.


Quote:
Originally Posted by Devil_Lord2 View Post
But yes I get you both.. I've always seen return ??? but never how it was used lol..
Thank you both!
Reply With Quote
Reply


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 09:40 AM.


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