The NJF Script Learning Topic
#31
Posted 31 March 2014 - 08:12 PM
Is it true you can literally turn off a script entirely by removing void run() from the script? Because if it cannot run, the script will just remain like that?
#32
Posted 31 March 2014 - 08:20 PM
Thanks DaviAwesome. I noticed though that you had "functionnamed" that was not proceeded by an "int" or a "void", but instead nothing altogether. But they also appeared to be a part of the already existing int.
Yeah, that's when you call the function so that it runs:
void FunctionName() { Link->X = 250; Link->Y = 250; } FunctionName(); //This is where you call the function that you created above. Basically, I made a custom function and then I have to call it somewhere in the script to activate it. It will not activate by itself otherwise.
Is it true you can literally turn off a script entirely by removing void run() from the script? Because if it cannot run, the script will just remain like that?
I am not entirely sure about this one, but I believe you are correct. You wouldn't need to do that though; there are ways to end a script if it reaches a certain point.
#33
Posted 31 March 2014 - 08:23 PM
A void function will end if a) It reaches the end of the function, or b) it reaches a line saying return;
A non-void function will end if it reaches a line saying return value; where "value" is a variable matching the type of the function.
- David likes this
#34
Posted 31 March 2014 - 08:24 PM
Also about the return statement. You can optionally end void functions by following return with a semicolon.
return;
- David likes this
#35
Posted 31 March 2014 - 09:08 PM
I must admit it will take me much time to understand what is being said. But I am taking a few days (or even weeks) practically living inside Saffith's basic guide he has provided here. What I mean by "living inside it" is that I will constantly read, reread, and absorb, and read more until I grow tired of seeing it over and over, and than read even more before I even consider looking at his intermediate stuff.
I may even choose a couple of months just grasping the basic stuff alone. But as far as specific questions go, that's what this topic is for. the basic guide can't answer many of my specific questions, and I indeed have specific questions.
#36
Posted 01 April 2014 - 09:10 PM
Link->HP = Link->HPWould the compiler see this as setting Link's HP to his already current HP? Or would this return an error?
#37
Posted 01 April 2014 - 09:25 PM
I think it would probably "work".
#38
Posted 01 April 2014 - 09:26 PM
Edited by DaviAwesome, 01 April 2014 - 09:27 PM.
#39
Posted 02 April 2014 - 02:51 PM
Would this be legal? Despite its uselessness:
Link->HP = Link->HPWould the compiler see this as setting Link's HP to his already current HP? Or would this return an error?
This is absolutely legal. Remember that = is assignment, not equality. So it translates to 'Assign Link's HP the value of Link's HP'. Note that this allows the type of expression: Link->HP = Link->HP + expression.
#40
Posted 02 April 2014 - 06:38 PM
- David likes this
#41
Posted 02 April 2014 - 09:14 PM
If so, are they the same arguments that appear in Zquest and therefore adjustable in Zquest?
Nevermind, I think I got the right answer now.
Edited by NewJourneysFire, 02 April 2014 - 09:17 PM.
#42
Posted 02 April 2014 - 09:33 PM
That's great, not that I could ever put it to good use, I find knowing what's legal is very helpful aid because it's telling me that I'm understanding.
You could totally put it to good use. Using a variable's old value when assigning a new value to it is one of the most basic but useful things you can do. It's used constantly in all sorts of scripts. As for return vs. arguments, think of arguments like input, and return as output.
#43
Posted 04 April 2014 - 10:55 AM
Correct. Like you said, otherwise the game will freeze forever.
Actually, what the game is doing is running the script an infinite number of times, every frame.
Waitframe tells the script to stop running for this frame, then continue again the next.
- David likes this
#44
Posted 04 April 2014 - 11:40 AM
#45
Posted 04 April 2014 - 02:25 PM
I believe I'm starting to understand functions, but it feels they were more difficult to understand than variables.
Are functions more or less the same as variables but just a different way of doing things?
Edited by NewJourneysFire, 04 April 2014 - 02:26 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users