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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top