Jump to content

Photo

The NJF Script Learning Topic


  • Please log in to reply
92 replies to this topic

#31 TheLegend_njf

TheLegend_njf

    Deified

  • Members
  • Real Name:Grant

Posted 31 March 2014 - 08:12 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.

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 David

David

    Fallen leaves... adorn my night.

  • Administrators
  • Real Name:David
  • Pronouns:He / Him

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 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

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 Mero

Mero

    Touch Fluffy Tail

  • Banned
  • Real Name:Tamamo No Mae
  • Location:Rainbow Factory

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 TheLegend_njf

TheLegend_njf

    Deified

  • Members
  • Real Name:Grant

Posted 31 March 2014 - 09:08 PM

This is all useful information.

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. :P the basic guide can't answer many of my specific questions, and I indeed have specific questions.

#36 TheLegend_njf

TheLegend_njf

    Deified

  • Members
  • Real Name:Grant

Posted 01 April 2014 - 09:10 PM

Would this be legal? Despite its uselessness:

Link->HP = Link->HP
Would the compiler see this as setting Link's HP to his already current HP? Or would this return an error?

#37 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 01 April 2014 - 09:25 PM

I think it would probably "work".



#38 David

David

    Fallen leaves... adorn my night.

  • Administrators
  • Real Name:David
  • Pronouns:He / Him

Posted 01 April 2014 - 09:26 PM

I think I'd technically work but, like you said, it doesn't have any use. :)

Edited by DaviAwesome, 01 April 2014 - 09:27 PM.


#39 anikom15

anikom15

    Dictator

  • Banned
  • Real Name:Westley
  • Location:California, United States

Posted 02 April 2014 - 02:51 PM

Would this be legal? Despite its uselessness:

Link->HP = Link->HP
Would 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 TheLegend_njf

TheLegend_njf

    Deified

  • Members
  • Real Name:Grant

Posted 02 April 2014 - 06:38 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.
  • David likes this

#41 TheLegend_njf

TheLegend_njf

    Deified

  • Members
  • Real Name:Grant

Posted 02 April 2014 - 09:14 PM

When writing functions, if I'm reading this correctly, the return types and return names are arguments?

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 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

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 symbiote01

symbiote01

    Doyen(ne)

  • Members
  • Real Name:Doug
  • Location:WA

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 anikom15

anikom15

    Dictator

  • Banned
  • Real Name:Westley
  • Location:California, United States

Posted 04 April 2014 - 11:40 AM

Remember you are in a loop when you call waiframe. Every frame, ZC has a queue of things to do. Eventually it gets to doing your script. It'll do everything up to the first waitframe, no matter how long it takes. If it sees a waitframe, it 'jumps' back to its queue and continues working until it's the script's turn again. It then starts where it left off, which is usually the end of a while loop. Thus, an iteration of the while loop occurs strictly once per frame when waitframe is called within the loop.

#45 TheLegend_njf

TheLegend_njf

    Deified

  • Members
  • Real Name:Grant

Posted 04 April 2014 - 02:25 PM

Is it just me, or are functions naturally a little bit more difficult to understand than variables?

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.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users