ID:2088751
 
(See the best response by Ter13.)
So the game im trying to fix up has some techniques where they use ALOT of separate vars for each of there own cooldowns (EX: used_aquajet=0)39 of these vars from what I count which is really stupid so I was wondering what can i do to replace this mess?


Best response
mob
var/tmp
list/cooldowns = list()
proc
Cooldown(id,duration) //set a cooldown to a specific length of time from right now.
cooldowns[id] = world.time+duration

setCooldown(id,time) //set a cooldown to a specific time in the future or the past.
cooldowns[id] = time

getCooldown(id) //returns what time a cooldown ends (might be null if it's never been on cooldown)
return cooldowns[id]

remainingCooldown(id) //returns how much time is left on a cooldown or 0 if it's off cooldown
return max(0,cooldowns[id]-world.time)

Write(savefile/F) //manually save the cooldowns as offsets because they are based on world.time. This will not persist between hosting sessions.
..()
var/wtime = world.time
var/list/l = list()
for(var/v in cooldowns)
if(cooldowns[v]>wtime)
l[v] = cooldowns[v]-wtime
F["cooldowns"] << l

Read(savefile/F) //manually load the cooldowns as offsets because they are no longer valid after having been saved. Adjust them to the current world time.
..()
var/wtime = world.time
var/list/l
F["cooldowns"] >> l
for(var/v in l)
cooldowns[v] += wtime
cooldowns = l


Boom. Cooldowns. One variable. Just use a string for ids. List association is awesome.
can you give me a sample of a what a skill might look like using this im new to using ids so not exactly sure on the proper coding and such


You've been here too long to be wasting anyone's time with that second question. The first question was reasonable. The second question is not. Use a string for the ids. Use relative or world time for everything else. I'm not even going to tell you to read the guide. If you don't know what a string is 10 years later, you haven't even read the first page of the guide.

Learn or don't learn. Figure it out.
"Terthebully"
Is it bad to use and save skillcard objects?
In response to Zagros5000
Zagros5000 wrote:
Is it bad to use and save skillcard objects?

it's bad to save any objects
it's bad to save any objects

Can you elaborate?

Is it bad to use and save skillcard objects?

Depends. Do you plan on changing the structure of the skills later? You probably don't need a skill object per player. A single global list containing one copy of all skills in the game and a set of ids corresponding to what skills a player has access to are probably more than enough information to be saving for skill usage in an unlock-based game.

These days, I'm leaning away from saving atoms because they are just too data intensive and too prone to breaking changes.
Ooh I can see the advantage of saving to a global list and giving players access instead of per player saving
In response to Ishuri
Ishuri wrote:
Zagros5000 wrote:
Is it bad to use and save skillcard objects?

it's bad to save any objects

Isn't it only bad to save objects if you're foolishly saving the icon itself and other data that you could easily load back in later? In short, don't have redundant data. Only save data you can't possibly get back (experience, location, a CHANGED name, etc.).
Pretty sure that's where he's going with it. The fact that overlays/icons etc. are marked as savable in the first place is kind of one of those things that shouldn't have happened IMO.