• 🏆 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] Can things like hashtables, triggers be constant?

Status
Not open for further replies.
Can things like hashtables, gamecaches, triggers be defined as constant globals when they won't be reassigned?

The reason I think they might not is that the actual object can change by storing/flushing values or adding events, conditions or actions.

Is there even a compelling reason to do it beyond ensuring that the variable won't be reassigned?
I imagine that there are no performance implications in JASS, or are there?
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
No they cannot, and there’s no reason to. I’m unaware of a significant performance difference for accessing constant integers vs regular integers (for example) but that may only be because the difference isn’t enough to be excited about.

The JASSHelper keyword to do what you want is readonly, which only allows setting of that variable within the scope it’s defined, but it can't be used in globals blocks, only struct member declarations.
 
Last edited:
Ah good to know. I only ask because I found myself wondering about this, as I have the habit of making variables constant whenever possible in C++.
So the constant keyword is kind of useless for private variables I suppose, especially with the readonly keyword, as long as you trust yourself not to reassign variables that shouldn't be.

Thanks =)
 
Status
Not open for further replies.
Top