• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

vJASS Questions

Status
Not open for further replies.
Level 7
Joined
Apr 30, 2011
Messages
359
  • Prefixes
    1. What does a static prefix do?
    2. What is the difference of a constant and a readonly prefixes?
    3. What is the difference of objects that use no prefixes with ones that use public prefix?
    4. Can we use stub prefix with variables?
    5. What does a type prefix do?
  • Objects
    1. How can we use functions as an argument?
    2. What do interface(s) do?
    3. Are globals(s) work like local(s) do?
 
Last edited:
Level 7
Joined
Apr 30, 2011
Messages
359
i don't understand < and > operators . . .
can anyone explain this ?

i really not understand this code:
JASS:
interface  wack
    //... some declarations
endinterface

struct wek extends wack
   integer x
   // some more declarations
endstruct

function test takes wack W returns nothing
   //You are certain that W is of type wek, a way to cast the value is:
 local wek jo = W
   set jo.x= 5 //done

   // but sometimes creating a variable is too much work for the virtual machine and you
   // are only accessing it once 

   set wek(W).x=5 //also works.
endfunction


type anarrayofdata extends integer array [6]

function getdata5 takes unit u returns integer
    //a reference to an object of type anarrayofdata is saved as the unit's custom value
    return anarrayofdata(GetUnitUserData(u))[5]
endfunction

function setdata5 takes unit u, anarrayofdata x returns nothing
    // Here we are doing the opposite, notice that integer may be used as a type cast
    // operator for struct and dynamic array types.
    call SetUnitUserData(u,  integer(x))
endfunction
please explain this too . . .

maybe just those . . . . .
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
What does a static prefix do?
Same as it does in JAVA. Not like it does in C.

What is the difference of a constant and a readonly prefixes?
constant is normal JASS. readonly is a macro instructing the precompiler how to treat something.

What is the difference of objects that use no prefixes with ones that use public prefix?
The namespace they share. No prefix means the object is added directly to the global namespace. The public prefix means it is added to the global namespace but with the scope / library prefix appended to it. This purly allows you to name functions the same internally without risk of name clashes. I comonly name all my initializer functions "init" which would normally cause a re-declereation syntax error but because I use the private modifier it garuntees that the precompiler will generate them unique function names. Like wise you might want a remote public init and destroy function for libraries so that code footprint can be kept down when a system is nolonger useful or is suddenly required during a session.

Can we use stub prefix with variables?
I think this is used to provide interface like functionality from JAVA.

What does a type prefix do?
Simlar to the system in C. It instructs the precompiler to create a new custom type. The result should be precompiler type errors if you do not keep the type usage consistent. Acts as a programmer aid more than functionality as it prevents one from getting variables and argument values mixed up as well as makes the code easier to read.

How can we use functions as an argument?
Using interfaces I believe. However the actual JASS way it gets implimented is eithor by passing a function name string and unit the appropiate call or by passing a trigger with a bound condition of the appropiate function. Arguments to the function and the return value are passed using global variables. JASS just does not support function pointers like C does sadly.

What do interface (s) do?
Prety silar to declaring a function type in C and in some ways simlar to JAVA interfaces. They define a function stub that you can use in your code as a type and call at certain times. Logically you will need functions with the same argument and return counts and types for this to work and to define such functions as using the interface. I described earlier how this sort of mechanic is implimented into JASS by the precompiler.

Are globals (s) work like local (s) do?
Globals work like global variables. Locals work like local variables. This is the same in every scripting and programming language I have learned. Globals get stored in the heap and can be accessed by any thread. Locals get stored in the thread specific stack and so can only be accessed within a thread. On top of that local declerations last until a function returns and the stack frame shifts back to the calling function while globals remain in memory indefinatly.
 
Status
Not open for further replies.
Top