PDA

View Full Version : use of <OnUpdate>


phobos
11-28-2004, 06:26 PM
I'm writing a little mod that keeps track of soul shards. I didnt want to have it have to be triggered to do a count, and I'd like it to update in real time. I have it looping through the bags/items on a <OnUpdate> function (starts with an if BAG_UPDATE() ), and its working well - I'm mainly concerned about any possible performance hits.

Is it a modding no-no to use <OnUpdate> for something like this? I'd imagine if someone had 20 or more OnUpdates running it would be a performance hit.

phobos
11-28-2004, 08:59 PM
I ended up doing an OnLoad and OnEvent instead of Update, but its probably still good to talk about.

sarf
11-28-2004, 09:31 PM
OnUpdate should be avoided at all times - mainly because there seems to be a performance hit from just declaring <OnUpdate>. :(

This is why Cosmos has CosmosSchedule, so you can use another OnUpdate function to do stuff at regular intervals or later.

Note: If you wish to do regular intervals, I really, truly recommend using Cosmos_ScheduleByName("IDENTIFIER", delay, command, args...) instead of Cosmos_Schedule(delay, command, args...) because if you happen schedule the same method again, it will simply overwrite the old scheduling function, instead of "stacking" the schedules... something I did with QuestMinion when I used Cosmos_Schedule for its Quest Fade thingy. :oops:

Anyhow... depending on what you want to do, you can often "get away" with using events as (somewhat) reliable "scheduled updates".
The event UNIT_HEALTH (with arg1 set to "player") gets called roughly every two seconds.

Of course, a "hackish" way of doing stuff would be to signup for loads of events then use a timer to see if you'd like to do stuff! :)

Sarf
---
CIRCUS, n. A place where horses, ponies and elephants are permitted to see men, women and children acting the fool.