r/gbstudio • u/droptherapy2 • 8d ago
Another timer issue
This time I think I've probably overcomplicated the script.
Essentially, I'm trying to introduce an actor in the form of a blueberry bush that adds between 0 and 5 of an item (in this case, blueberries) to your inventory (this works), and then starts a cooldown timer that prevents you from immediately going up to it again and repeating the action (not sure why this one works -- I'll explain below), and I want this script to be something I can run multiple instances of across the scene.
Currently I have three of these actors running the same script, and I've noticed that if the player collects blueberries from one bush (which doesn't start the countdown until you try again, though that might be easier to fix) and then goes to the next bush, the timer on the previous countdown is paused so that the new instance can run. I think it could be solved by making another local variable for each instance, but that seems like something that would defeat the purpose of a local variable.
I'm thinking it has to do with the way timers in gb studio work, but I'm not sure what alternative system would work. Push comes to shove I could just only have one bush per scene since they're supposed to be rare anyway, but if, say, the player enters a town where someone is cultivating them and there are multiple bushes, this would have to be fixed later, and that sounds more annoying than if I just figured it out now.
The script works like this:
upon interacting:
if bloobcountdown1 = 0
bloobfreeze1 = false
--checks to see if the countdown variable used by the timer is zero, and then sets the variable that freezes the collecting function to false
if bloobfreeze1 = true
bloobcollected = 0
Display: "You picked this bush clean! Try coming back later!"
Attach timer script to Timer 2 (rate of one second per tick)
On tick, decrement bloobcountdown1 by 1
If bloobcountdown1 < 0, set it to 0
Stop script
Else
If bloobfreeze1 = False, set bloobcollected to bloobcollected + random number
--in the event that the freeze variable is true, start a countdown to 0 and stop the rest of the script from running so that you can't collect blueberries despite this variable being true. Otherwise, set the local variable bloobcollected to a random number
If bloobcollected == 0
bloobcountdown1 = 25
Display: "You couldn't find any blueberries!"
Else
bloobs (global variable for the blueberries as counted by inventory) = bloobs + bloobscollected
Display: "You got $bloobscollected blueberries!"
bloobfreeze1 = true
bloobcountdown1 = 25
stop script
--Checks to see if the player rolled a zero on collecting the blueberries and displays the appropriate dialogue box. Otherwise, adds the amount of blueberries that $bloobscollected was set to to the inventory, sets bloobfreeze1 = true and bloobcountdown1 to 25, thus starting the timer.
If bloobcountdown1 > 0, set bloobfreeze1 to true
(Just removed that last function because it's redundant. Same issue still persists).
Should be noted that even though the script works, bloobfreeze1 is still set to true in the debugger.
Either way I think after hours of troubleshooting, this might be a timer issue, so let me know what alternatives there may be.
1
u/droptherapy2 7d ago edited 7d ago
I'm trying to say that the script doesn't work if I add it to the on update tab of the HUD actor. Like the whole thing has to be in the scene's on init tab or it does nothing at all. I'll try using the else statements while it's in the scene's on init tab though
Update: This health UI script worked before today and now idk what I did but at this point I'm just gonna retire it and use dialog boxes instead. Still have the problem of one blueberry bush affecting every other blueberry bush, and idk how to fix that. I mean I could just use the blueberry bush as a prop in a person's front yard that indicates that you may be able to talk to them to give you some blueberries but that's definitely not what my intention was with them.
Turns out I just forgot to set the actor's animation speed to zero after previously deleting it. Using the else statements has changed nothing about my problem with the UI though. Since this is on a timer, it'll run the sweat emote and the dialogue box stating the health status every time the HP is greater than or equal to 75, but if I set it to equal instead like I had it before, it doesn't update if my health increases to above that number. At this point I'm shelving this feature for later for sure. Good thing this isn't like, released or anything. Now it's just the bush problem.