• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Question about Variable and Indexing

Status
Not open for further replies.
Level 7
Joined
Apr 18, 2010
Messages
102
Do you need to have a new variable name for each "MUI, Index, Caster" in each spells or is it possible to only have different "MUI" names for each spells but the "Caster" variables are the same..for example, on one spell the variables are Caster[MUI_1] and Target[MUI_1] (lets say that the dynamic indexing was done already) and on another spell its Caster[MUI_2] and Target[MUI_2]... will there be errors?? if not, then can i extend this thought to have a variable named MUI[x] so that there will be only 1 "MUI" named variable... basically the spells would have variables like "Caster[MUI[2]], Target[MUI[2]]" and the so on and so forth? Sorry for the bad grammar =D
 
Level 7
Joined
Apr 18, 2010
Messages
102
in that tutorial the user made us of the variable SL_<insert something> and SL_Index and SL_Loop, what I am asking is, is it possible to use 1 single variable for all the would be casters in a map that has many spells? example a skill called omnislash would use a variable named "Spell_Caster" while another spell, ie, Void, would also use that same variable for storing its caster, they would basically differ in the variable in that array , (the one inside the []).

something like this
trigger 1:

Spell_Caster[MUI[1]] = Triggering unit (casted by unit A)

trigger 2:
Spell_Caster[MUI[2]] = Triggering unit (casted by unit B)

lets say that the two triggers are running at the same time but have different casters.

would the variables overlap each other? just curious so that i wont have to create tons of variables for every spell i make =D.
 
Level 22
Joined
Feb 6, 2014
Messages
2,466
You could always use JASS with JNGP so that you can declare your global variables within the script and not have to go in the bloody Variable Editor. That way, all are organized and can be put in a single trigger (I meant the trigger in the left side of Trigger Editor). It is easier in my opinion.
 
Last edited:

Zwiebelchen

Hosted Project GR
Level 35
Joined
Sep 17, 2009
Messages
7,236
If I take your question literally, then you are asking if nesting array indices is possible.

Which I can answer with "yes":

Spell_Caster[SpellType[SpellInstance]] is possible.

However, this will not solve your problem. If MUI[1] and MUI[2] (which are terrible variable names btw, which is why I renamed them to SpellType[SpellInstance]) contain the same value, then Spell_Caster can and will be overwritten by the later instance allocated.


What you actually want is a two-dimensional array like:

Spell_Caster[SpellType][SpellInstance]


Unfortunately, this is only possible in vJass. But you can use Hashtables, which basicly work the same as two-dimensional arrays.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
I meant global variables. The variables in the Variable Editor are globals. Plus, using local variables in GUI is a pain in the ass.

Local variables aren't even legal in GUI. The whole thing must be custom script. You can try variable shadowing, but it will be broken with an optimizer. You also get the wrong value when you try to reference it from a GUI if-block. Just not worth it at all.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
I meant global variables. The variables in the Variable Editor are globals. Plus, using local variables in GUI is a pain in the ass.

So JNGP allows you to create global GUI variables without entering the variable editor or whatever that window is called?

I've been using JNGP wrong for 3 years if that's true...
 
Level 22
Joined
Feb 6, 2014
Messages
2,466
So JNGP allows you to create global GUI variables without entering the variable editor or whatever that window is called?

I've been using JNGP wrong for 3 years if that's true...

I'll repeat:
You could always use JASS with JNGP so that you can declare your global variables within the script and not have to go in the bloody Variable Editor.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
JASS:
globals
    integer myIntegerVariable = 12345
    string myStringVariable = "blablabla"
    trackable somethingThatIsImpossibleToMakeWithoutThisMethod
    handle somethingThatIsImpossibleToMakeWithoutThisMethod
    widget somethingThatIsImpossibleToMakeWithoutThisMethod
    agent somethingThatIsImpossibleToMakeWithoutThisMethod
endglobals

As you can see, there are quite a bit more variables that you can make with this method.
Also, no restrictions of name length :D
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
For something to be categorized as vJASS, it must be compiled by the JASSHelper.
Not much room for opinions.

However, you have plain JASS code in vJASS (normal functions, normal variables, normal stuff inside library tags or global tags) and struct JASS which is basically code that includes structs and/or access modifiers.
Only those two have any difference in how you write the code and some people are just more skilled in one of them.

Neither are bad but hard to use together.
 
Status
Not open for further replies.
Top