HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[Question] Other functions other than "function"

12-08-2007, 12:03 AM#1
Tiku
Okay so in some spells/systems i've seen some other things rather than functions. I dont really understand much of difference in them, and i was wondering if you guys could tell me what the others do..

By functions i mean:
Collapse JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

I've seen more things like:
Collapse JASS:
method onDestroy takes nothing returns nothing
        set .whichboard = null
    endmethod
(A Script from Ammorth's MultiBar system)

as well as private functions and static
Collapse JASS:
private method UpdateBoard takes nothing returns nothing


static method create takes multiboard whichboard, integer colstart, integer row, integer size, integer divisions, real maxval, real currentval, string bartype, string filetype, string directory returns MultiBar
(Another Script from Ammorth's MultiBar system)

and i've seen other things such as natives, as well as structs, library, and scope:
Collapse JASS:
native
struct
library
scope

I was wondering what exacly is the difference from these and just normal function, and what does constant function do rather than just function, oh and what are globals exacly?

Thanks in advanced!
12-08-2007, 01:06 AM#2
Ammorth
methods exist inside structs. They are like the functions for manipulating structs.

method onDestroy is called when you would call struct.destroy(). It is used to clean-up variables (in my case, the multiboard) when a struct is destroyed.

Private prefix entitles that the author does not want the function to be called outside the system, or the function should not be used outside the system. Trying to call a private function will not work outside the system, since it is given a random integer in the name which prevents it from being called.

Private prefix can also be used to make sure there are no conflicts with names of functions between systems.

Static method is a method that does not take a struct reference. They are usually used for create methods. When you call a method, you usually do somestructvar.somemethod() where somestructvar is passed to somemethod so it can be modified by the method. A static does not take a struct, so you would call it by using structtype.somestaticmethod to call somestaticmethod within the struct structtype.

natives are functions which exist in common.j They are what warcraft III runs on.

struct is an object which you can store variables, and create method for. They are used all over the place for various reasons (extending UserData, physics systems, etc.)

library allows for private and public prefixes within the library. They also move the script to the top of the map, so all code can call it. Some libraries may require others, so use the requires keyword to specify which libraries it uses

scope is like library except it doesn't get moved to the top of the script.
12-08-2007, 01:10 AM#3
Anopob
Besides the function one, method struct etc. needs vJass, and "oh and what are globals exacly?" They are pretty much variables that aren't local (in which they don't need to be used in that function only).
12-08-2007, 02:06 AM#4
Tiku
Wow... thanks alot Ammorth! (I feel sarcastic whenever i say that, but its not sarcasm here :P)

Seriously thanks, i finally understand the differences... but i need to reread some of the stuff to understand it more, unfortunatly i cannot +Rep you, :( but thanks again for the help, and thanks anopob