• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[vJASS] General vJass questions

Status
Not open for further replies.
Level 16
Joined
May 1, 2008
Messages
1,605
Moin moin =)

Since I started with vjass, there are some things, I don't know/understand, so I want ask some general questions here, to get it clear:

1) What is the difference between "(private) static method" and "(private) function"? Does warcraft calculate them different? When yes - how?

2) Why I can't use "(private) functions" in a "(private) struct" at all?

3) In vJass-spells inside the struct, I always use "static method". Does something happen, when I only type "method" in? - At least what's the meaning of this "static"?

4) Is there a difference between "static if" and a normal "if". When yes - what kind of difference and when I need to use what?

5) Why is it better, to have a "private struct" instead of a normal "struct"? Thought names of this can't be used twice anyway.

6) When I started with vJass and wrote the struct, I always wrote first the create method and under this method the periodic method. I remember that someone said it has to be the other way round, first the periodic method and under this the create method? But why that? (I never asked him)

7) Does it makes a difference when I type only "static method periodic takes nothing returns nothing" instead of
"private static method periodic takes nothing returns nothing"?

8) What can be the reasons, that triggers doesn't work in a library but in a non library? [I made a trigger, which runs when a dialog button is clicked of a dialog. I put this trigger into a library and it doesn't work. A friend said then, I should try it without the library and it works, but he said he don't know why this is so - someone else know it?]

9) What is the difference between a scope and a library?

== Not directly vJass ==

10) In a normal trigger in the init function, why the trigger doesn't work, when I use this way:
JASS:
function InitTrig_InitTeams takes nothing returns nothing
    local trigger t = CreateTrigger()
    
    call TriggerRegisterDialogEvent(t,udg_Dialog)
    call TriggerAddAction(t,function InitTeams_Actions)
    
    set t = null
endfunction

instead of this:

JASS:
function InitTrig_InitTeams takes nothing returns nothing
    set gg_trg_InitTeams = CreateTrigger()
    
    call TriggerRegisterDialogEvent(gg_trg_InitTeams,udg_Dialog)
    call TriggerAddAction(gg_trg_InitTeams,function InitTeams_Actions)

endfunction

What makes the local thing not working (in this case)? In some other cases it works =O


Well this would be all for the moment. I want say, that my English isn't that good, so if some people feel free to answer some questions, then please don't come up with an high-quality-super-uber-English, which I don't understand anyway =)

Thanks - Greetings - Peace
Dr. Boom
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Answers for 1, 2, 3, 4, 5, 7 can be found in jasshelper manual http://www.wc3c.net/vexorian/jasshelpermanual.html

6) The order of methods doesn't matter except sometimes when you implement a module that uses one of methods from your struct. In that case, the implementation should be below that method.
EDIT: Although...if you call methods like startPeriodic() from T32, create method should be below.

8) Can't help without the code.

9) Library is moved to map header which means it's functions can be used from anywhere. Score is just a group of functions or such that isn't moved to header. It's main purpose is just to give you ability of using private keyword so that the variables names don't appear twice.

10) It works in both, except that you can't use ExecuteTrigger function when you use a local trigger because, obviously, you didn't assign event and action to the global generated trigger variable.
 
Level 26
Joined
Mar 19, 2008
Messages
3,140
Okey since someone created such thread I add few other questions:

- What generally module is

- thats the difference between normal initializatize function and implement init spammed in vJass (thus init comes on the top of trigger instead of bottom

- Whats general difference between method and function

- Whats the general meaning of static

@Dr. Boom - about 10. question, I'm afraid but since gg_trg_InitTeams is global declared in map script, so you shouldn't declare it again. First method (with local) seems fine - meaby actual name of trigger doesn't match init function one - check if both share 'InitTeams'.
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
(private) static method and (private) function, basically is the same, the difference I see is that methods can be called in any position (up or down) within the struct while functions can only be called up...
JASS:
//you cant do this...
private function test takes nothing returns nothing
    call test1
endfunction

private function test1 takes nothing returns nothing
    call BJDebugMsg("OK")
endfunction


struct blah

//this is possible...
private static method test takes nothing returns nothing
    call thistype.test1()
endmethod

private static method test1 takes nothing returns nothing
    call BJDebugMsg("OK")
endmethod

private static method test3 takes nothing returns nothing
    call thistype.test1()
endmethod

endstruct

private word ensures that the function/method can only be used inside the given scope/library...
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Okey since someone created such thread I add few other questions:

- What generally module is

- thats the difference between normal initializatize function and implement init spammed in vJass (thus init comes on the top of trigger instead of bottom

- Whats general difference between method and function

- Whats the general meaning of static

@Dr. Boom - about 10. question, I'm afraid but since gg_trg_InitTeams is global declared in map script, so you shouldn't declare it again. First method (with local) seems fine - meaby actual name of trigger doesn't match init function one - check if both share 'InitTeams'.
-You need to know what a struct is to understand what a module is.
-What's implement init? If you mean module init, then it's just an initialization function that, because of execution order, gets executed first among init functions.
-Methods are struct's functions. If not static, they hold current instance which can be refered to as 'this'
-depends where it's used. Static method, for example, doesn't hold current instance while static struct member is just like a global variable.

It would be best to read jasshelper manual then ask if you don't understand something.
 
Level 22
Joined
Nov 14, 2008
Messages
3,256
1. They're the same but methods can only be within structs and functions outside.

2. Yes you can as long as they're within the same scope/library. Although the private function needs to be ontop of the struct to make it "call-able" else you'll need keywords and keywords suuuuuck.

3. Makes it to a typical function and doesn't hold its previous value (or how to say it)

4. The difference is that a static if will compile the code if it returns true and not if it returns false. Basically that code within will be commented out if not. Very good for spells with preload stuff which you can put into a static if and have a constant boolean to check if a user wants to preload or not ( will have impact onto the loading time usually )

5. As public structs can be reached from other triggers by extending to them (if you accordingly has "required" the library from another library) while private cannot be extended too.

6. I'm not sure about this one, either readability or something else but I cannot remember the real deal.

7. Within a private struct? No (well I think my T32 module compiled wrong when it was public but maybe not the reason). If it's in a public struct but it's a method which is useless to other structs to call then yes.

8. Have no idea without code.

9. Libraries are put into the map header's thus compiled before scopes and makes all public functions in a library reachable for scopes.

10. Forgot most of the JASS knowledge I know of so no idea.

@Spinnaker
1.
A module is like a code package you can place in a struct to gain extra methods or members, etc. module, ..., endmodule are used to declare a module and implement is used to copy the module's members to the struct. Consider this as a high level textmacro.

Found in the manual. Probably the best way to describe it.

2. It's just that they use a module initializer which they implement into the struct as module initializer (due to grim001 telling Vex to do this) compiles first.

3. Methods are within structs and functions outside.

4.
A static if is what I explained above.
A static method is a normal function within a struct.
A static struct member is a global.
There should be more but I cannot really recognize them in my head at the moment.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
A method using another method must be below that method.


method a
method b
->call a()


Yes, you can order them however, but vjass will turn the calls into trigger evaluations if they are out of order.

method b
->call a()
method a

That call a() is no longer a simple function call. It is a trigger evaluation wrapped in a function call. Order your methods appropriately.


The reason that a module calling code must be below that called code is because of this order.

module b
method c

If b calls c, those calls will be trigger evaluations. This can destroy you in resources like T32.

method c
module b

If b calls c, then it is a regular function call.
 
Level 16
Joined
May 1, 2008
Messages
1,605
Moin moin =)

First of all big thanks for the answers - I think I understand everything you said =P

@Garfield1337: Well I took a look into this manual, but I have my problems with understand this there, for me it's x-times more complicate then (for example) baassee said it, this why I wrote my questions here^^

Anyway - thanks to all
Greetings and Peace
Dr. Boom
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Right, so then in that case it would throw syntax errors when you
wanted to call a method below another method without putting
.evaluate()?

That's the point, yes.

You have to edit the jasshelper.conf which is in the JNGP folder, i mean not the one in the jasshelper subfolder (read the first comment of the file), but if you use jasshelper only i suppose this file has to be in the same folder of jasshelper.exe

from the official jasshelper documentation :

# 0.9.Z.4

* Reversed the deprecation of automatic method TriggerEvaluate, you may enable the syntax error adding [forcemethodevaluate] to jasshelper.conf.

It appears only on the changelog, no where else.

Edit: Double post.

== Not directly vJass ==

10) In a normal trigger in the init function, why the trigger doesn't work, when I use this way:
JASS:
function InitTrig_InitTeams takes nothing returns nothing
    local trigger t = CreateTrigger()
    
    call TriggerRegisterDialogEvent(t,udg_Dialog)
    call TriggerAddAction(t,function InitTeams_Actions)
    
    set t = null
endfunction

instead of this:

JASS:
function InitTrig_InitTeams takes nothing returns nothing
    set gg_trg_InitTeams = CreateTrigger()
    
    call TriggerRegisterDialogEvent(gg_trg_InitTeams,udg_Dialog)
    call TriggerAddAction(gg_trg_InitTeams,function InitTeams_Actions)

endfunction

What makes the local thing not working (in this case)? In some other cases it works =O

It's not local related, it's more function name initializer related.

If you don't use a vJass initializer (scope,library or module/struct), but keep the GUI initializer, you have to spell the function initializer like that :

InitTrig_TriggerName

But really, just use the vJass initializers with the private statut ...
 
Last edited by a moderator:
Status
Not open for further replies.
Top