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

[General] Hashtables, Arrays or Local Variables, which one is the best to achive MUI?

Status
Not open for further replies.
Level 3
Joined
Jun 19, 2014
Messages
26
As I searched throught the forums, I found those methods to achieve MUI, however I haven't found any explicit pros and cons of one over the others.
What would you say about them?

PS: As local variables, I mean the Shadowing technique
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
You can achieve MUI with local variables.

Some mora advanced features may also require some vJASS

Some more advanced features may also (or not) require an Unit Indexer (Bribe's suggested).

Some more advanced stuff may also (or not) require a Hashtable
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
If you use vJASS you can easily have MUI for your systems (I am assuming it's a spell system?). Just design your own unit wrapper via struct.

JASS:
library myStruct

globals
endglobals

struct myStruct
  unit u
  static method create takes unit u returns thistype
     local thistype this = thistype.allocate()
     set this.u = u
     return this
  endmethod
  //put any functions here that each unit has
  //i.e. your code goes here
endstruct
endlibrary

So whenever you make a unit, you would need to make sure to put it into its own wrapper. But as p0ke said, it would help if you know exactly what you are doing, and why your current approach isn't working.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
All 3 have their purposes. Hashtables are good for mapping arbitrary values such as to units and things. Arrays are good for creating allocable data structures. Locals are used to avoid clogging the map with excessive arrays and allow nested code.

Generally arrays should be used for bulk data as they are fastest. Hashtables should be used for efficient lookup of mappings such as an index on a unit or a timer. Locals generally have nothing to do with MUI and are more a useful scripting tool.
 

EdgeOfChaos

E

EdgeOfChaos

All 3 have their purposes. Hashtables are good for mapping arbitrary values such as to units and things. Arrays are good for creating allocable data structures. Locals are used to avoid clogging the map with excessive arrays and allow nested code.

Generally arrays should be used for bulk data as they are fastest. Hashtables should be used for efficient lookup of mappings such as an index on a unit or a timer. Locals generally have nothing to do with MUI and are more a useful scripting tool.

Locals are related to MUI. Example:

Unit starts the effect of an ability
Set Caster = Casting Unit
Wait 5 seconds
Kill Caster

^ Not MUI

Unit starts the effect of an ability
local unit caster = Casting Unit
Wait 5 seconds
call KillUnit(caster)

^ MUI
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Locals are related to MUI. Example:

Unit starts the effect of an ability
Set Caster = Casting Unit
Wait 5 seconds
Kill Caster

^ Not MUI

Unit starts the effect of an ability
local unit caster = Casting Unit
Wait 5 seconds
call KillUnit(caster)

^ MUI

not true. Or bad example at least.


  • Untitled Trigger 001
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Wait 5.00 seconds
      • Unit - Kill (Triggering unit)
  • Untitled Trigger 002
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Custom script: local unit udg_caster
      • Set caster = (Triggering unit)
      • Wait 5.00 seconds
      • Unit - Kill caster
both are MUI.
 

EdgeOfChaos

E

EdgeOfChaos

not true. Or bad example at least.


  • Untitled Trigger 001
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Wait 5.00 seconds
      • Unit - Kill (Triggering unit)
  • Untitled Trigger 002
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Custom script: local unit udg_caster
      • Set caster = (Triggering unit)
      • Wait 5.00 seconds
      • Unit - Kill caster
both are MUI.

My example is quite true. I used global variables with event response, not just event responses. Yes, I know some event responses are MUI, but in my example the global would be overwritten. It was meant to show the principal that global variables lead to non-MUI (when not using arrays/hashtables) and locals lead to MUI code.

Obviously you wouldn't have to use locals, you could just use event response in my example. But this is not always true; sometimes you need variables and waits, and globals just don't cut it. It was just an example of how locals can make code MUI, not "this is an excellent use of locals"
 
Status
Not open for further replies.
Top