Just wondering, I have a while loop that I am using to update a shop interface purchase button, based on the players income. So if they have the shop open and obtain enough money to purchase an item while it's open, the purchase button becomes active.
Does I need to put a wait time in the loop, will it effect performance or anything if I don't? It is updating dialog items for players, but I think it will only run clientside?
Should I at least put a 0.1 second wait in the loop?
[UPDATE] Since people keep replying without reading the other replies:
Yes it is bad to use a while loop without any wait
It's probably not that bad to use it with a wait only if you have to
99% of the time you shouldn't need a loop, create a function and make it state driven instead (i.e. the function is only run when something happens).
I created a function that updates an individuals players shop, this allows me to call the function when their income changes, or other related states change.
Functions accept parameters so they are much more useful than triggers for this sort of thing
The entire purpose of having triggers is that you don't need to implement game loops whether they be monolithic or threaded. You're on a completely wrong approach.
I'd say you should try to avoid triggers running continuously if you don't absolutely need them to. Don't know how much of a performance hit you'd take if you'd do it your way though. Adding a 0.1 sec wait would probably be quick enough.
...or you could run the shop interface update trigger when "Player - Player 1 Custom Resource changes".
I have a loop going and it doesn't seem to matter that it goes through the trigger like 50 times, of course that's a little different than it lasting the whole game's duration; however, the game is constantly checking for trigger events and conditions to be met, so I don't think a couple of loops are going to make much of a difference. While I'd rather not have them because I'm OCD like that, they do what they need to do.
That being said, I think Riley has a point, depending on how your shop is set up. I could see a chain of 'if/then' actions in a single trigger. Something like:
any unit enters region of the shop
if money < 100
then open shop 1
else
if money <1000
then open shop 2
else
if money <2500
then open shop 3
etc.
I'm currently new with the if/then stuff but something like that would be a little easier (and for someone OCD like me, better) than constantly checking for the player's money and updating the shop on the fly when it can be canned into an activated trigger.
The entire purpose of having triggers is that you don't need to implement game loops whether they be monolithic or threaded. You're on a completely wrong approach.
Is using a while loop with a wait any different to using a trigger with a periodic timer?
There are a few different ways to approach it, but it all comes down to:
the difference between a while loop with a delay and a periodic timer event
the impact on performance, if anything substantial, that either periodic method has
p.s. my shop is a fully custom interface, i'm not talking about a shop like in wc3 where you walk near a building and press the button to buy something.
So the shop is constantly open, or do you have to click a button to make the window pop up. A button click is still triggerable
The main difference between a period event and a wait time action is that the wait time action requires an event to trigger it where as with the period event, it is the trigger, and therefor much easier to work with.
You press a button to open the shop, then select an item to view before you purchase it (a weapon) which displays a dialog with the weapon details and the preview button. I can update the details on the button click, but they still get income while the shop is open, so I want the interface to reflect those changes while the interface is open without them having to click the item again, it's just more polished that way.
Anyhow, after playing around with custom functions I've changed this so that the shop dialog just updates whenever the players money changes, this way I don't need any sort of periodic timer, and the shop items always display correct states based on the money the player has.
This is really only possible using the functions and not triggers as far as I can tell, since the function allows me to specify which player I want the dialog to update for.
...or you could run the shop interface update trigger when "Player - Player 1 Custom Resource changes".
Tried and didn't work, or did it get lost in the other replies?
It doesn't matter if you are customizing everything, there are events for most things you'd want to do anyway. And when there isn't, bend your other triggers a bit. For this scenario, there are a ton of different player properties you can choose from. If a players income only exists inside a variable and a custom display, either mirror his income to credits, minerals, custom resource or something or simple use a player property instead of a variable to store a players income.
Read above a few posts guys, I solved this by creating a custom function that I can call to update an individual players shop display when their income changes. I just pass it the player number parameter.
It's much better than messing with triggers, because with triggers you can't specifically tell it to update for player X all of the time.
It's a bit simpler now too because I use one dialog for all players for the item preivew. Previously I was using one for each player purely because you can't seem to change the dialog title per player, so I changed this to a label.
Ah, nice. I've been wanting to make a function, but never really had a reason to do so. I considered it briefly here, but didn't get into it since I haven't done any functions yet. Great example here on a situation where a function is very useful.
Guess I was tired when I posted my last post. Totally missed that you had got it working well.
I would recomend a workaround of simply putting a "refresh button" there... then the player can deal with it (piss less players off when it switches just before they try to buy something)
If you want to update it automatically still, find an event dealing with their income and attach it to the event. Events will be MUUUUCH less overhead (read: "lag") than a constantly running contiuous timer like that.
I would recomend a workaround of simply putting a "refresh button" there... then the player can deal with it (piss less players off when it switches just before they try to buy something)
If you want to update it automatically still, find an event dealing with their income and attach it to the event. Events will be MUUUUCH less overhead (read: "lag") than a constantly running contiuous timer like that.
I don't think a refresh button is good interface design and it is a bit of a cop out.
If you want to update it automatically still, find an event dealing with their income and attach it to the event. Events will be MUUUUCH less overhead (read: "lag") than a constantly running contiuous timer like that.
I don't think you read the previous posts before you posted, as stated I am using a function to update this now, no loop involved :). Viva la functions!
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Just wondering, I have a while loop that I am using to update a shop interface purchase button, based on the players income. So if they have the shop open and obtain enough money to purchase an item while it's open, the purchase button becomes active.
Does I need to put a wait time in the loop, will it effect performance or anything if I don't? It is updating dialog items for players, but I think it will only run clientside?
Should I at least put a 0.1 second wait in the loop?
[UPDATE] Since people keep replying without reading the other replies:
The entire purpose of having triggers is that you don't need to implement game loops whether they be monolithic or threaded. You're on a completely wrong approach.
I'd say you should try to avoid triggers running continuously if you don't absolutely need them to. Don't know how much of a performance hit you'd take if you'd do it your way though. Adding a 0.1 sec wait would probably be quick enough.
...or you could run the shop interface update trigger when "Player - Player 1 Custom Resource changes".
I have a loop going and it doesn't seem to matter that it goes through the trigger like 50 times, of course that's a little different than it lasting the whole game's duration; however, the game is constantly checking for trigger events and conditions to be met, so I don't think a couple of loops are going to make much of a difference. While I'd rather not have them because I'm OCD like that, they do what they need to do.
That being said, I think Riley has a point, depending on how your shop is set up. I could see a chain of 'if/then' actions in a single trigger. Something like:
any unit enters region of the shop
if money < 100
then open shop 1
else
if money <1000
then open shop 2
else
if money <2500
then open shop 3
etc.
I'm currently new with the if/then stuff but something like that would be a little easier (and for someone OCD like me, better) than constantly checking for the player's money and updating the shop on the fly when it can be canned into an activated trigger.
Is using a while loop with a wait any different to using a trigger with a periodic timer?
There are a few different ways to approach it, but it all comes down to:
p.s. my shop is a fully custom interface, i'm not talking about a shop like in wc3 where you walk near a building and press the button to buy something.
So the shop is constantly open, or do you have to click a button to make the window pop up. A button click is still triggerable
The main difference between a period event and a wait time action is that the wait time action requires an event to trigger it where as with the period event, it is the trigger, and therefor much easier to work with.
You press a button to open the shop, then select an item to view before you purchase it (a weapon) which displays a dialog with the weapon details and the preview button. I can update the details on the button click, but they still get income while the shop is open, so I want the interface to reflect those changes while the interface is open without them having to click the item again, it's just more polished that way.
Anyhow, after playing around with custom functions I've changed this so that the shop dialog just updates whenever the players money changes, this way I don't need any sort of periodic timer, and the shop items always display correct states based on the money the player has.
This is really only possible using the functions and not triggers as far as I can tell, since the function allows me to specify which player I want the dialog to update for.
@KratsAU: Go
instead of a loop, why not make the trigger trigger when you gain income? =o it wont run as often as a loop that runs once every 0.1 seconds.
Tried and didn't work, or did it get lost in the other replies?
It doesn't matter if you are customizing everything, there are events for most things you'd want to do anyway. And when there isn't, bend your other triggers a bit. For this scenario, there are a ton of different player properties you can choose from. If a players income only exists inside a variable and a custom display, either mirror his income to credits, minerals, custom resource or something or simple use a player property instead of a variable to store a players income.
Read above a few posts guys, I solved this by creating a custom function that I can call to update an individual players shop display when their income changes. I just pass it the player number parameter.
It's much better than messing with triggers, because with triggers you can't specifically tell it to update for player X all of the time.
It's a bit simpler now too because I use one dialog for all players for the item preivew. Previously I was using one for each player purely because you can't seem to change the dialog title per player, so I changed this to a label.
Ah, nice. I've been wanting to make a function, but never really had a reason to do so. I considered it briefly here, but didn't get into it since I haven't done any functions yet. Great example here on a situation where a function is very useful.
Guess I was tired when I posted my last post. Totally missed that you had got it working well.
It's cool, functions are really easy to work with too, no doubt I will be using them more often now - very handy indeed!
I am glad I don't have any loop in there now, it was working fine but I really wasn't happy with it, hence why I posted here in the first place.
I would recomend a workaround of simply putting a "refresh button" there... then the player can deal with it (piss less players off when it switches just before they try to buy something)
If you want to update it automatically still, find an event dealing with their income and attach it to the event. Events will be MUUUUCH less overhead (read: "lag") than a constantly running contiuous timer like that.
I don't think a refresh button is good interface design and it is a bit of a cop out.
If it switches off just before they buy something it's because they can't afford it anymore, so you should not be letting them purchase it anyway.
I don't think you read the previous posts before you posted, as stated I am using a function to update this now, no loop involved :). Viva la functions!