wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Warcraft III Modding > Developer's Corner > Triggers & Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 05-07-2007, 03:05 AM   #1
Joker
User
 
Joker's Avatar
 
Join Date: Sep 2006
Posts: 687

Joker will become famous soon enough (32)Joker will become famous soon enough (32)

Default Questions on Structs/Globals

I saw this post that emjlr3 had posted on TheHelper site
Quote:
Originally Posted by emjlr3;458499
it basically allows you to create a variable that holds many different variables in it

for ex.

Collapse JASS:
struct blarg
 real x
 real y
 unit hero
 unit targ
 real ang
 real dist
endstruct

//when you then get the struct, or create it later

local blarg dat = blarg.create()

//you can then store your variable values, or get them, jsut by using their names

blarg.x
blarg.y
blarg.dist

//etc.

therefore, all you need transfer between functions in the integer dat, using game cache

in the end, this should be much faster and safer then using gc for all of it

and it didnt seem that bad. Is this all there is to it to a struct?

Do you need some additional scripts for structs?

Also, what are methods, and private functions?

A question not really related to Structs:
does this create a global variable in the script? if not, then what does it do? Do they have to be nulled?
Collapse JASS:
globals
    local unit a
endglobals

Last edited by Joker : 05-07-2007 at 03:05 AM.
Joker is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 05-07-2007, 03:29 AM   #2
Mezzer
:emote_grin:
 
Mezzer's Avatar
 
Join Date: Nov 2004
Posts: 841

Submissions (1)

Mezzer has a spectacular aura about (77)Mezzer has a spectacular aura about (77)Mezzer has a spectacular aura about (77)

Send a message via MSN to Mezzer Send a message via Yahoo to Mezzer
Default

You need to use the Jass NewGen Pack which contains vJass, which allows you to use that syntax. Basically, it's a program which will go over your script and change it into something that WC3 can understand.

Here's the link for the pack.

And here's a user's guide for vJass.

And that global block gets appended to the global declaration of the map, so making a variable local in there makes no sense.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.

Last edited by Mezzer : 05-07-2007 at 03:31 AM.
Mezzer is offline   Reply With Quote
Old 05-07-2007, 03:30 AM   #3
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

For your questions:

Quote:
Do you need some additional scripts for structs?
No, only this tool: http://www.wc3campaigns.net/showthread.php?t=90999

Quote:
Also, what are methods, and private functions?
Methods are functions inside the functions which can be used to manipulate the data in the struct.

Private functions are functions that are only valid inside the library or struct defined. Methods are private functions for the struct, for instance.

About your question about the globals, it will generate error, it should be:
Collapse JASS:
globals
    unit a
endglobals


For more information about structs and more improvements to JASS, read this.

Last edited by moyack : 05-07-2007 at 03:30 AM.
moyack is offline   Reply With Quote
Old 05-07-2007, 04:39 AM   #4
MaD[Lion]
MaD Da ViNci
 
MaD[Lion]'s Avatar


Respected User
 
Join Date: Apr 2003
Posts: 1,699

Submissions (10)

MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)

Default

I have to fix moyack a bit :)

Methods are nothing more than functions inside struct. They are used to manipulate variables/data inside this struct, which functions cant.
Why they are called method dont ask me. You can call them functions if u want :P
Just that if we talk aboit method, then we know: ok we are talking about functions inside struct.

private functions or private variable are variables that can only be accessed inside a scope.
A struct has it's own scope, also does a library.
You can also use private functions without declaring libraries or structs, bu just declearing the scope.

Private functions is very nice if you only want your system to use a function, but not let anything else run it outside the scope. This way it's more secure.

example i always use:
Collapse JASS:
private method onDestroy takes nothing returns nothing
...
endmethod
Cus i dont want people to clean up anything before the object is destroyed.

If you dont know, onDestroy will be called every time u destroy a struct.
---

And why did u think of declaring locals inside globals, that doesnt make sense.
You dont want a global if you want a local, and you dont want a local if you want a global, not both :P
__________________
Current Projects:
MaDOS (outdated)System for object movements & effects - NEW VERSION IS UNDER W.I.P
Cinematic SystemSystem for making better cinematics and with fancy effects
Timing SystemTiming system that simulates the usage of PolledWait just with 0.01 accuracy

Last edited by MaD[Lion] : 05-07-2007 at 04:40 AM.
MaD[Lion] is offline   Reply With Quote
Old 05-07-2007, 05:41 AM   #5
Toink
User
 
Join Date: Oct 2006
Posts: 1,086

Submissions (3)

Toink is on a distinguished road (17)

Send a message via Yahoo to Toink
Default

Private functions cannot be called by functions outside the scope/library it is in.

Scopes are just like libraries, except that they do not get moved to the top of the script.

Opposite to the private functions and/or variables, there are the public members.. Publics are similar to privates except that they are able to be called by a function outsite the scope/library they are in. For example..

Collapse JASS:
scope blah

    globals
        unit u // If you declare globals inside a scope/library, it cannot be used by functions outside the scope/library, which means you can have 10 different globals named u in 10 different scopes/libraries.
    endglobals

    private function MyFunc takes nothing returns nothing
        call KillUnit(u) // Kill the unit 'u' ?
    endfunction

    public function MyPubFunc takes nothing returns nothing
        set u = GetTriggerUnit()
        call MyFunc() // Calls the private function
    endfunction

endscope

function Func takes nothing returns nothing
    call blah_MyPubFunc() // The syntax to call a public is <SCOPENAME>_<Function Name>
endfunction


Hope that also helped you :/

But you should just read the manual included in the JASS NewGen pack.
Toink is offline   Reply With Quote
Old 05-07-2007, 08:23 AM   #6
MaD[Lion]
MaD Da ViNci
 
MaD[Lion]'s Avatar


Respected User
 
Join Date: Apr 2003
Posts: 1,699

Submissions (10)

MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)

Default

ye that manual explains everything. DOnt try to understand all, jsut try to make one thing work, before going on the new one
__________________
Current Projects:
MaDOS (outdated)System for object movements & effects - NEW VERSION IS UNDER W.I.P
Cinematic SystemSystem for making better cinematics and with fancy effects
Timing SystemTiming system that simulates the usage of PolledWait just with 0.01 accuracy
MaD[Lion] is offline   Reply With Quote
Old 05-07-2007, 08:52 PM   #7
Joker
User
 
Joker's Avatar
 
Join Date: Sep 2006
Posts: 687

Joker will become famous soon enough (32)Joker will become famous soon enough (32)

Default

Ty guys :) I think im finally making some progress on structs. Also, i meant not to put the "local" in my global. My bad =P so back on the question
Quote:
Originally Posted by me
does this create a global variable in the script? if not, then what does it do? Do they have to be nulled?
Joker is offline   Reply With Quote
Old 05-07-2007, 09:12 PM   #8
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Toink: what you said about the global variable u would only be correct if you added the "private" prefix to it's declaration.

MaD[Lion]:
Quote:
Methods are nothing more than functions inside struct. They are used to manipulate variables/data inside this struct, which functions cant.
Wrong, the only struct members that cannot be manipulated by outside functions are the ones with the private prefix.

I've seen more errors/odd use of words in the thread, but can't be bothered to read it again. Joker, just read the JassHelper documentation that Mezzer linked to, things are pretty well explained there. As for your question, struct members are nothing more than global variable arrays, that's why you can't have more than 8191 structs of the same type at once, due to the array size limit. As globals, the individual variables in a struct don't need to be nulled, the thing that you have to watch out for is to destroy dynamicaly created structs when you no longer need them, else you risk hitting that size limit.
__________________
Anitarf is offline   Reply With Quote
Old 05-08-2007, 04:58 AM   #9
MaD[Lion]
MaD Da ViNci
 
MaD[Lion]'s Avatar


Respected User
 
Join Date: Apr 2003
Posts: 1,699

Submissions (10)

MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)MaD[Lion] is a jewel in the rough (225)

Default

well im not wrong, you can with functions only if you do struct.var, but u cant change it with the var name directly. But ok your right :P
__________________
Current Projects:
MaDOS (outdated)System for object movements & effects - NEW VERSION IS UNDER W.I.P
Cinematic SystemSystem for making better cinematics and with fancy effects
Timing SystemTiming system that simulates the usage of PolledWait just with 0.01 accuracy
MaD[Lion] is offline   Reply With Quote
Old 05-08-2007, 05:17 AM   #10
Toink
User
 
Join Date: Oct 2006
Posts: 1,086

Submissions (3)

Toink is on a distinguished road (17)

Send a message via Yahoo to Toink
Default

Quote:
Originally Posted by Anitarf
Toink: what you said about the global variable u would only be correct if you added the "private" prefix to it's declaration.

Ooh, right. Sorry about that.

Quote:
Originally Posted by Joker
does this create a global variable in the script? if not, then what does it do? Do they have to be nulled?

Time for a little lesson on variables..

First I'll answer your question. Yes. That creates a global variable in the script. However, if you declare globals inside a scope or library they cannot be used by other functions and you can name them without having a problem, BUT be careful, if you do not add the prefix 'private' it can be used by functions outside the scope/library. For example:

Collapse JASS:

globals
    unit u
endglobals

scope blah
    globals
        private unit u // Notice that we use the name u again. This global can only be used inside the scope it is in, in this case in blah.
    endglobals

    private function PrivFunc takes nothing returns nothing
        call KillUnit(u)
    endfunction

endscope

function Func takes nothing returns nothing
local unit blarg = GetTriggerUnit() //We are declaring a local variable, if you're not sure what locals are, they are exactly like globals [b]except[/b] that they are only used in the function they are in, in this case it is in Func
    call KillUnit(blarg)
    set blarg = null //We are setting variable to null. This is because this variable will leak memory. Why? Because it can only be used in one function remember? 
endfunction //And if the function(Func) executes/triggers again, it declares a different variable named u and [b]does not[/b] overwrite the previous variable. So the variable stays in your computer's memory.


Globals do not need to be nulled. This includes privates. Why? Because globals are overwritten when their values are changed. And globals can also be used by every trigger and function except for private globals.

Collapse JASS:

globals
    unit u
endglobals

function Func takes nothing returns nothing
    set u = GetTriggerUnit() // Sets the value of the global u
    call KillUnit(u) // Kills the unit u
endfunction

Notice that I did not nullify it. Why? When the function triggers again it actually overwrites the value of the global.

Hope that helped you. I spent some time making this stuff just to explain it to you, so show some appreciation by giving us rep if we did help you.

If you got more questions go to the Tutorials section, you'll find answers.

Last edited by Toink : 05-08-2007 at 05:21 AM.
Toink is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 08:01 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2020, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services