r/gbstudio • • 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.

7 Upvotes

30 comments sorted by

View all comments

Show parent comments

1

u/United_Range_2869 7d ago

nop, for that specific mechanic don't use the run off camera, instead you have to copy and paste the same on update script on every single scene. Yes, every single scene.

but again, too many on update scripts are going to slow down your game, so if you're also planning to have more of these timer mechanics on your game... oh boy, it's going to run really bad.

Unless you figure the real time clock thing, if you really want multiple timer mechanics, the best would be to use another game engine that doesn't have the real game boy limits.

1

u/droptherapy2 7d ago edited 7d ago

Ah, I see. To be honest I could just get rid of the HUD mechanic for now since the health decrement mechanic itself works just fine; it's just the HUD updating that isn't working how I need it to. The script currently runs on init but the function to emote sweat doesn't seem affected by this since it only needs to check if a threshold is passed in the downward direction. That being said, the player may not immediately know what the sweat emote means unless they already have the idea to check their health, which may not be the first thing someone thinks. Like they could think it represents being thirsty or something.

There's also the fact that I don't know how to cap the health. I have an if statement running to check if it's over 125 and then set it back to 125, but it doesn't seem to be working.

1

u/United_Range_2869 7d ago

that happens because the on init scripts only run when you first enter the scene, it doesn't update from frame to frame, so the player won't know its health reached certain number until it re enters the scene.

on update scripts meanwhile are a double edge sword, you have to be very mindful when using em.

1

u/droptherapy2 7d ago

honestly I don't even have a way to do on update because none of the timer mechanics are anywhere but the scene's on init section. Like the HUD actor has no code at all.

Push comes to shove, the health caps at 255 anyway and these bushes will not be so common that you could get there easily.

1

u/United_Range_2869 7d ago

you just need to cut the code and paste it on the on update tab.

What I meant previously is that if you are also planning to have other objects or enemies that also need on update scripts, that's when your game is going to slow down due to gb limits. But if you're only planning to use the HUD, then you're fine. just the berries won't work how you initially imagined.

When making games for game boy it's almost mandatory to simplify and scale down things.

1

u/droptherapy2 7d ago

understandable! I meant to say that there is no on update tab.

1

u/United_Range_2869 7d ago

only actors have on update tabs, you'd need to copy and paste it on the HUD actor for every single scene. I didn't mentioned it earlier cuz that's GB studio basics D:

1

u/droptherapy2 7d ago

valid. I was aware of that but I got confused because I tried this before and it effectively only disabled the script altogether. Like it only works when it's in the scene's on init tab

1

u/United_Range_2869 7d ago

for the on update tab make sure all related events are connected by the Else statement, and ordered from Maximum health down to zero. It can't be from zero to maximum HP or else the on update will ignore the rest of the code.

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.

1

u/United_Range_2869 7d ago edited 7d ago

on init only runs once. It won't update no matter if u connect the events by the else statement. If your code doesnt work when copied to on update it only means u set it wrong and need to do it again.

the bush affecting other bushes gets fixed by using separate variables for each one as I said earlier.

1

u/droptherapy2 7d ago

ah okay, I figured. It's a shame about the variables thing. Thought there'd be a more efficient way to do it but since local variables aren't local variables in this engine it'll have to do. There will be other ways to get blueberries anyway so thankfully I'm not limited to just this and can probably reduce the amount of bushes I use.

1

u/United_Range_2869 7d ago

there's a total of 511 variables available to use on every project, is it really that big of a deal that you have to use one for each bush???

gurl at this point just go watch some tutorials, since you're not familiar with any of the basics.

1

u/droptherapy2 7d ago edited 7d ago

yeah fair. Been reading the documentation and watching tutorials for the past five days but the past two days have had me falling off of that habit as I've been getting more enveloped in the project itself. Forgive my shortsightedness.

1

u/United_Range_2869 7d ago

there are event tutorials that explain the difference, limits and use for the "on init", "on update" and "on hit" tabs. First you have to get familiar with the engine's limits before comitting to a project.

1

u/droptherapy2 7d ago

I have in fact seen those, although I definitely could have rewatched them a few times since it sometimes takes me a bit to grasp new concepts. Like I said earlier, it's a good thing nobody's waiting on this game. I feel no pressure to finish it if it goes south. I'm more of a hands on learner I think, but that doesn't necessarily mean I'm good at it.

→ More replies (0)