Structs vs Globals

S

sinners_la_b

Guest
Now that we have scopes and such why even use structs if we can use globals. With globals i dont need ABC or any other system to pass the struct from one function to another. So why not just use globals.

sinners
 

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
i think it's because structs won't cause the same problems with MUI as globals does though im not an expertin structs so i don't know for sure....
 

Vexorian

Why no custom sig?
Reaction score
187
Ignore Cohadar's link, it is totally unrelated to your question.

Your question is quite lame, it is mostly like "why not use a fork instead of using a knife"? You are kind of making a false dichotomy as if globals and structs were meant to solve the same problem, when they are meant to solve different problems.

In short, your post seems to come from a huge misunderstanding on what structs or globals are. Please post some of your code in which you "replace structs with globals" so it is easier for us to prove you wrong.
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
How about explaining in laymans terms how to use the two?
 

Cohadar

master of fugue
Reaction score
209
Ignore Cohadar's link, it is totally unrelated to your question.

Vexorian is right here, I gave the wrong answer.
Or perhaps you made the wrong question sinners_la_b.

@Uareanoob
Structs are not globals, they are globals + methods + create + onDestroy + ...

@chovynz
There are a lot of tutorials on the subject of structs no need to explain that in here.
 

Silvenon

New Member
Reaction score
19

Is that your ABC?? What a surprise! You really don't post your ABC as an answer to every question. (Q: "hey, how do I create a unit?" A:"use my ABC")

Or perhaps you made the wrong question sinners_la_b.

There are no wrong questions, just wrong (stupid) answers.

@Uareanoob
Structs are not globals, they are globals + methods + create + onDestroy + ...

He meant the base of structs ffs. You said "structs are not globals, they are globals.....". Hahaha!! :)
 

Cohadar

master of fugue
Reaction score
209
Now that we have scopes and such why even use structs if we can use globals. With globals i dont need ABC or any other system to pass the struct from one function to another. So why not just use globals.

sinners

Now he specifically used ABC in his question for no reason.
Do not talk about ABC with no reason or I send some people to deal with you...
:cool::(:shades:

----------------------

Structs are NOT globals, they are parallel global arrays (synchronized with .this) + an internal array indexing capability.

STRUCTS ARE INTEGERS.
 
S

sinners_la_b

Guest
Cohardar i just used ur system as an example becuase thats what i use to pass structs from one function to another sorry if i upset you.

Now, i was at the understanding that structs were created to stop using handle vars and such (this is probably wrong) however i still need to use 'a' system that passes the structs from one function to another.

so like this

JASS:

scope wateva
globals

unit c

endglobals

function 2 takes nothing returns nothing

// do wateva to c

endfunction

function 1 takes nothing returns nothing

set c = GetTriggerUnit()
call 2()
endfunction
endscope


in the above i dont need to pass the structs from one function to another
however if i used structs i would.

Maybe i am getting the completely wrong idea here lol (wuldnt be the first time)

woot 100 posts

sinners
 
Reaction score
333
If you wanted to transfer multiple variables, you would have to use multiple globals. If you used structs, you would only need one global variable (an integer) to pass the data.

You only need to attach things to handles if there is going to be some sort of delay between one function and the other (as in the case of timers, triggers, etc).
 

Silvenon

New Member
Reaction score
19
Structs are NOT globals, they are parallel global arrays

So global arrays aren't globals? Oh, too bad.

I think what you meant to say is that they aren't just globals, they have many other components
 

Cohadar

master of fugue
Reaction score
209
So global arrays aren't globals? Oh, too bad.

I think what you meant to say is that they aren't just globals, they have many other components

No I specifically did NOT want to say just.

Global arrays being the only method of allocating memory in jass are used for struct implementation, that is totally specific to jass and does not exist in other programming languages.

If there was an alternative memory allocation in JASS (like it exists in normal programming languages) there would be no need to use globals to make structs.

Globals just happened to be the solution in this case, and are absolutely not necessary to make structs speaking in general terms.

Therefore structs are NOT globals, and not even with just attached.


sinners_la_b said:
Maybe i am getting the completely wrong idea here lol (wuldnt be the first time)

Yes and no.
Structs were not made to replace handle vars.
They were made to give more power to jass programming.
Structs are nothing more than a cloning of stuff from normal programming languages like c++/java/c# ...

You CAN use structs or globals to avoid attaching to timers
(as shown in the link I gave above)
But it is too much of a hussle if you ask me.
(just look at the link)

Now I want to make this very clear:
I use structs/globals for timers when speed is absolute requirement,
I made a physics(jumping) system with structs alone (no ABC)

But in day to day spellmaking I use ABC because it is so much easier to use simple ABC function calls than to mess with all that array stuff.
(again look at the above link)

ABC also has a benefit of being a "fool-proof" system,
witch means that it has built in error control, so it is virtually impossible to make errors with it without getting a message.

And lastly structs/globals will not help you when you need trigger attachments, and what better system to use for that than ABC :p
 

Pyrogasm

There are some who would use any excuse to ban me.
Reaction score
134
Before you all eat each other with linguistic technicalities:

What do structs consist of? Global arrays.
How are the structs themselves referenced? As integers.
 

Cohadar

master of fugue
Reaction score
209
Excuse me but terminology is extremely important in programming.

A consist of B <> A is B
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top