[SOLVED] Need help creating an idle regeneration system

Started by Icey, Tue 12/05/2015 15:37:07

Previous topic - Next topic

Icey

Hello everyone, the subject title might be a little bit from what I'm actually doing, so giving the fact that I'm not quite sure that's the correct term of what I'm trying to pull off here I'll simply just explain a bit of what I'm trying to do and the errors I keep resulting with.

Code: ags


//When pressing the rest mode button
function Button56_OnClick(GUIControl *control, MouseButton button)
{
DateTime *dt = DateTime.Now;
   Time = dt.Minute;
SetMultitaskingMode(1);
gGui7.Visible = true; 
}


//Room 11 checks for gui starts my consistent failing code]
function room_RepExec()
{
   if(BattlePoints == 100){
     
   }
   
   
else if(gGui7.Visible == true){
   DateTime *dt = DateTime.Now;
   
  if(dt.Minute >= Time){
  BattlePoints += 1;
  
  Time = dt.Minute;
  
}
}
}





A feature in my game is called [REST MODE], which allows you to build back battle points whilst leaving your game running idle.
But I can't for the life of me get this right, it could be possible it's in the wrong spot but I don't really know how to get it to give 1bp per minute for up to 100bp max.

I guess it's not working right because it's in the repeatably execute function but I can figure out where else to put it. :\

Gilbert

Haven't thoroughly read the codes, but how does the code not work? Does the regeneration never happen, or does it only regenerate for "some" minutes and then stops there?

If it is the latter, one problem I can see is that dt.Minute ranges from 0 through 59, so say when the time now is at minute 59, a minute later it would become 0, which is not larger than 59, so the regeneration will stop there. To really compare time you need to also take into account hour and, day, etc. (in case the clock hits 0:00). HOWEVER, as what you need here is to check whether the minute digits have changed, so instead of "if(dt.Minute >= Time){" try changing it to "if(dt.Minute != Time){" to see if that makes a difference.

Khris

Unlike the global repeatedly_execute, a room's RepExec() is only called if the player actually is in that room currently. So the first, obvious question: is Button56 only clickable in Room 11? Because if not, chances are room 11's RepExec will not get called.

The next problem is the fact that if the player happens to rest at minute 59, DateTime.Minute will return 0 next. Also, you're using if(dt.Minute >= Time), which will be true immediately after Time is set to dt.Minute by the button, meaning BattlePoints will rapidly count up to 100 within 2.5 seconds tops.

I'd simply do this using a timer: SetTimer(1, 60 * GetGameSpeed());
In the global repeatedly_execute, check for IsTimerExpired(1), increment BattlePoints and if below 100, restart the timer.

Icey

#3
@Gilbert: What happens is it works as planned but it keeps on running the loop,  At one point I actually got it to start once the minute was +1 higher than the store minute that was taking from the last minute on the clock. I change around the code a bit and now it just starts it off right away, which is still not what I want be either of the two ways just made the ran the Battlepoint += 1; section on loop until it maxed out at 100. It basically stops when I want it too and I had it where it started when I wanted it but what I need for it to do is to reset the timer after ne point. However, I should add that once I added Time = dt.Minute; beneath Battlepoint += 1; it would start doing the instant adding again until it hit 100.

@Khris: yeah that's exactly what's happening, the second part that is. I just didn't take that into the consideration with the way things would be calculated. But I'll give that a shot right now, thanks guys.

Update: Thanks Khris, that did the job. Now I can finally continue on with the of the game. :grin:

SMF spam blocked by CleanTalk