• 🏆 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!

[Solved] A way to call upon independent variables based on the player triggering the event?

Status
Not open for further replies.
Level 8
Joined
Mar 17, 2016
Messages
133
Hi all,

I'm finding myself caught up in all sorts of mathematic problems lately, something I'm not the greatest at solving on my own. I want to have a trigger that will go something like this:


Event triggered by "Player (X) presses a button for a dialog box"
(The dialog box will have multiple options, let's say there's 4 for this particular one.)

If the player picks option 1, it will add +1 to a variable with the 1st array, eg.
Set PickedOption[1] = PickedOption[1] +1
If they pick #2, it will do the same thing to the 2nd array of "PickedOption".


What I need help with is how to do this using a temp player variable, something that every time the trigger is fired it will set the player that activated it as the current player. So it would do the above mentioned functions, but each player would have their own counter and they are called upon based off of who most recently pressed a button/fired the trigger.

So, if player 1 has PickedOption[1] at 5, and player 2 gets a +1 counter to PickedOption[1] it will only affect it for that player, and red's counter will remain at 5.

The reason this is necessary to do with a universal trigger, and not have a different trigger for each player, is because I'm planning on having 21 questions and 38 options per question (funnelled into say, 4 choices). I would need to set around 800 variables individually x5, as my original intention was to have 5 separate variables - Player1Options, Player2options, etc. If I screw one up I would have a hard time noticing that there's something wrong for that specific player having to search through 5 long, tedious triggers.

I hope I'm explaining this right, if someone needs me to clarify I would be happy to do so.
 
Level 12
Joined
Feb 5, 2018
Messages
521
Set tempinteger = player number of triggering player

Set tempplayer[tempinteger] = yourplayer

Something like this could work.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
Why not use a 2 dimensional array? These can be emulated from a 1 dimension array using some basic mathematics.

Say you want a 2D array that is X_MAX by Y_MAX size. The following mathematics can be used to resolve an index from a 1D array that is (X_MAX * Y_MAX) sized.
ARRAY2D[y][x]
ARRAY1D[y * X_MAX + x]

Of course maximum 1D array sizes apply.
 
Level 8
Joined
Mar 17, 2016
Messages
133
Why not use a 2 dimensional array? These can be emulated from a 1 dimension array using some basic mathematics.

Would this method require me to set each of the variables individually? Because essentially what I'm trying to avoid is having 5 different triggers (or if/then/else's) that each have a condition for a different player activating it. I've never used 2D arrays and could be mistaken, but it seems that if I was to use this method I would still need to manually adjust each of the 38 variables per question 5 times (once for each player's choices).

Set tempinteger = player number of triggering player

Set tempplayer[tempinteger] = yourplayer

I tried to get this to work, but I couldn't manage to figure out a way to use it in a universal trigger because (I'm assuming that) I need the variable that tracks the choices to be an array.



Actually, I think I may have just found my solution thanks to the suggestions. I'm thinking that if I was to change the format of which variable uses what array, as in:

Instead of using the variable "PickedOption" as the array that holds all 38 potential options I will just make 38 variables, one for each option and have those with 5 arrays each. This is where "TempPlayerInteger" would come in, setting each of the 38 answers independently based on what player has most recently triggered the event.

Unless this is obviously wrong in some way that I don't understand I'll probably just go with this method. Or maybe this is why the 2D array would work well... I'll probably wait until tomorrow before going through with this, just in case its actually a terrible way of going about this- as 2D arrays are just another thing I do not understand whatsoever.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
Would this method require me to set each of the variables individually? Because essentially what I'm trying to avoid is having 5 different triggers (or if/then/else's) that each have a condition for a different player activating it. I've never used 2D arrays and could be mistaken, but it seems that if I was to use this method I would still need to manually adjust each of the 38 variables per question 5 times (once for each player's choices).
Index 1 -> Player Slot Number
Index 2 -> Question Number, Choice Number, Whatever you want.

Still not enough indices? Maybe a 3D array would be the solution...
Index 1 -> Player Slot Number.
Index 2 -> Question Number.
Index 3 -> Choice Number.

That way the same trigger than be used to process all players. Such is the advantage of data driven systems.
Instead of using the variable "PickedOption" as the array that holds all 38 potential options I will just make 38 variables, one for each option and have those with 5 arrays each. This is where "TempPlayerInteger" would come in, setting each of the 38 answers independently based on what player has most recently triggered the event.
Or just use a single multi dimensional array. Or a hashtable. Or if using Lua some nesting of different tables.
as 2D arrays are just another thing I do not understand whatsoever.
Say you want a 2D array that is X_MAX by Y_MAX size. The following mathematics can be used to resolve an index from a 1D array that is (X_MAX * Y_MAX) sized.
ARRAY2D[y][x]
ARRAY1D[y * X_MAX + x]
By default in JASS arrays have a maximum size of JASS_MAX_ARRAY_SIZE.
JASS:
constant integer JASS_MAX_ARRAY_SIZE=32768
As long as the product of the axis sizes is less than JASS_MAX_ARRAY_SIZE then it can fit in a single JASS array.

So for example say there are 24 players with 38 questions and 5 answers each. This has a total product of {24 * 38 * 5} or 4,560. This is less than the current JASS_MAX_ARRAY_SIZE so can fit within a single JASS array.

The logic to access an element from such a 3D array...
Array1D[PlayerSlotNumber * (38 * 5) + QuestionNumber * 5 + AnswerNumber]

As long as the indices are kept the valid index range for each dimension the logic will guarantee a unique storage space for that combination of indices within the backing 1D array.
 
Status
Not open for further replies.
Top