Better way of reloading the game? My current method is causing some bugs.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
ken.athomos
Citizen
Posts: 77
Joined: Fri Aug 05, 2016 10:13 am
Location: Philippines

Better way of reloading the game? My current method is causing some bugs.

Post by ken.athomos »

Good day everyone!

Currently doing my third game project. It's a simple twitch-based game (not the streaming service). You basically change your color to "phase through" the falling blocks. Technically, I've done all of the core mechanics that I need (minus the collisions) but the way I'm trying to reset certain variables to their defaults are causing some slow down bug.

The bug is that when am restarting for a new game, there are still some left over blocks from the previous instance that are slowly falling down instead of not being there.

I was wondering if it's how I've programmed the game and specifically the resetting of values that's causing this issue? I really want you guys two cents on this one. (While we're at it, I would really appreciate it if someone would discuss to me the best way of handling the reloads, as well as any stupid or improper thing I've done)

So this is how you can replicate the bug:
  1. Start a New Game.
  2. On the Game State, wait until there are at least 2 blocks on the screen.
  3. When there are at least 2 blocks on the screen, press the "Escape" button to pause the game.
  4. On the pause screen, press "Escape" again to return to the Title screen.
  5. Start a New Game again.
By this time you'll see at least 1 block that's slowly (sometimes not even) falling go down.

EDIT: I'm not using any libraries btw and I would currently refuse to do so for this project for the sake of learning.

Thanks in advance to anyone who is going to reply to this post.

Also please pretend that I'm a five year old when explaining stuff to me if that's okay :P

Huge shoutout to xNick whose been entertaining my questions for the past few days now :D
If you're wondering why I'm not messaging him again about this, it's because I already feel bad for asking a lot of consecutive questions XD
Project 3.love
Project 3 - Twitch-based Game
(4.45 KiB) Downloaded 125 times
User avatar
xNick1
Party member
Posts: 267
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Re: Better way of reloading the game? My current method is causing some bugs.

Post by xNick1 »

You forgot to reset those 2:

Code: Select all

blockID = 0
blockTime = 35
so:

Code: Select all

elseif key == 'escape' then
	 	selectedState = 'title'
		redBlocks = {}
		greenBlocks = {}
		blueBlocks = {}
		colorState = 1
		timer = 0
		score = 0
		blockID = 0
		blockTime = 35

	end
They're local, so you need to make them public.

That made the trick for me
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Better way of reloading the game? My current method is causing some bugs.

Post by raidho36 »

Next version of love will have special functionality for this.
User avatar
ken.athomos
Citizen
Posts: 77
Joined: Fri Aug 05, 2016 10:13 am
Location: Philippines

Re: Better way of reloading the game? My current method is causing some bugs.

Post by ken.athomos »

@xNick1 thanks for helping me on this. Really means a lot.

@raidho36 can you explain about the special functionality pls? (or leave a link?) thanks!
User avatar
xNick1
Party member
Posts: 267
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Re: Better way of reloading the game? My current method is causing some bugs.

Post by xNick1 »

ken.athomos wrote: Thu Jun 08, 2017 11:38 am @xNick1 thanks for helping me on this. Really means a lot.

@raidho36 can you explain about the special functionality pls? (or leave a link?) thanks!
Does it work now?
As far as you reset all the local vars it should start again as fresh.
User avatar
ken.athomos
Citizen
Posts: 77
Joined: Fri Aug 05, 2016 10:13 am
Location: Philippines

Re: Better way of reloading the game? My current method is causing some bugs.

Post by ken.athomos »

Yehp it works now. Like you said, I just had to make sure they aren't local vars anymore :)
Post Reply

Who is online

Users browsing this forum: No registered users and 122 guests