• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • It's time for the first HD Modeling Contest of 2025. Join the theme discussion for Hive's HD Modeling Contest #7! Click here to post your idea!

Afraid of an integer going over limits...

Status
Not open for further replies.
Level 3
Joined
Jan 11, 2018
Messages
23
So here's what i'm working with:
  • BuildStationAndGiveItValue
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to Working Station
    • Actions
      • Set AmountOfWorkingStations = (AmountOfWorkingStations + 1)
      • Unit - Set the custom value of (Constructed structure) to AmountOfWorkingStations
It's essential that every Working Station has its own custom value. There's one problem here: The custom value integer might go overboard at some point, and i'd like to find a way that if a Working Station gets destroyed it would free up a slot, so to speak, lets say there's currently 100 working stations on the map, working station n.70 gets destroyed, custom value slot 70 gets unlocked and if someone was to build a new station it would have the custom value of 70. So is there a better way of making this system? Nothing really coming up for me right now.
 
Level 43
Joined
Feb 27, 2007
Messages
5,432
What do you mean by "overboard"? The integer limit is fucking massive and I don't think the game could even last long enough to build that many of them. If you are using the CV in array indexes then you can still get up to ~32,000 before jumping THAT limit. Also probably functionally impossible in a game, even if all 24 players were building them.

Proper Dynamic Indexing is, of course, the better solution (and you should learn how to do it because it's an essential process in programming) but I'm not confident you have to worry about it here.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,264
The custom value integer might go overboard at some point
I highly doubt it will before the game has long since crashed. You are looking at producing 2,147,483,647 buildings before that happens. Even the most spammy tower defense/hero defense/zombie map/RPG struggles to make it past 100,000 units created and destroyed. In fact I do not recall ever seeing that happen.

To put it in perspective, to hit that limit in a 10 hour game one would have to create at least 59,653 units per second for 10 hours. Even the fastest modern computer could not manage that at full speed let alone with playable frame rate.
So is there a better way of making this system?
Use a unit indexer system. These assign a unique custom value to every unit. Custom values are recycled when units are removed. This is done by keeping a "free list" of custom values that is taken from first before allocating new custom values. Such systems commonly also provide a handy "unit is removed" style event which is better than a unit dies event when it comes to freeing resources since dead units may be subject to resurrection.
 
Status
Not open for further replies.
Top