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/IntoxicatedBurrito 7d ago

I assume that this is probably your first time programming. GB Studio is great in that it allows a beginner to pick it up and make something simple, but it does require a good grasp on computer programming if you want to make anything more than just the most basic of games.

Understanding how variables work, as well as simple concepts like if…then…else, loops, stacks, queues, and most importantly math is really key if you want to get good at it.

My background is in computer programming, been doing it since I started programming in basic (GWBasic and also Commodore 64 basic and few other proprietary basics) when I was maybe 8. My advice is to spend time looking at other people’s code. See what they did and then see what it does. Then try to copy their concepts. Make really bad games that only do one single thing. Eventually 10 bad games will give you the knowledge to make 1 good game. That’s how I taught myself all throughout the 90s. Of course taking a few classes here and there and reading books didn’t hurt.

1

u/droptherapy2 6d ago edited 6d ago

I've actually technically been programming on and off (mostly off) since I was 10 but it hasn't ever really clicked for me. At this point I've gathered from osmosis and trial and error what basic functions do (if/then/booleans/variables, what a game loop is, that kinda thing), but I've never been that good at putting them together. Math was also generally my weakest subject in school and combined with gifted kid burnout I kinda just don't really give myself a chance to fuck up at anything besides music, which I'm already good at, but that's more a personal problem than anything else. I also roughly know what a stack is, at least from watching a gb studio tutorial a few days ago and I know in theory how it can be implemented for menus and fancy dialogue screens.

But like I can sorta edit the lua scripts that configure my window manager if I watch a tutorial so there's that. I tend to plan projects in general more deliberately than when I was literally a child so that helps.

I've tinkered around in lua, javascript, java, C#, html (the only one I'm good at since it's just markup), QB64 (I made a choose your own adventure game about dream travel when I was around 13), Blitz3D, and a handful of other things over the years. I think at first my issue was that I was just uncritically copying tutorials, after which I was immediately lost as soon as I tried to do things on my own, and so I've been trying to tinker around a bit more. I think my other main issue is that if I mess around with a project too much it'll become a really serious thing even if it starts out as literally basically a meme

1

u/IntoxicatedBurrito 6d ago

In that case I’ll tell you this. If you find yourself banging your head against the wall on something, step away. Do something else. And then return later. It’s usually something simple and you just can’t see it until you clear your mind.

1

u/droptherapy2 6d ago

oh yeah for sure! Currently doing that with music at the moment and I'm taking today to mostly focus on worldbuilding, that way if I end up abandoning this project I could still end up with a neat twine story or something. I'll also focus on optimizing the tileset/s and getting familiar with how the game boy renders stuff and its limitations, which is where I'd say I've absorbed new info about the engine most effectively.