Discord
Login
Community
DARK THEME

Score doesn't work at all, NEED HELP ASAP(before Friday, this is very important)

The variable for the score in my game doesn't want to increase, and it is really bad because I have to print this variable, and it also decides the outcome of the game. [Candy = class

constructor = function(x, y) this.x = x this.y = y end

visible = true

candyColllisionCheck = function()

if distance(player.x, player.y, x, y) < 16 then

  numCandy += 0.3

  this.visible = false

end 

end

end ] <- this is the class that creates candies and it is also supposed to increase the variable numCandy (which is declared in the main init function) by 1 everytime the playey touches the candy. The candy dissapears as it is supposed to after the touch, but the variable numCandy doesn't increase

[ init = function()

numCandy = 0

player = object

x = 0

y = 0

s = 1.5

w = 20

l = 30

image = "walk_down"

end

candy1 = new Candy(-97, 70)

end] <- this is the init() function, in case it is needed

[candy1.candyColllisionCheck()] <= this is how I called the function in the updateGame()function, which is later called in the update()

[ screen.drawText("Candies collected: " + numCandy + "/9", -52, 90, 10,"rgb(0,23,15)" ) ] <- and this is how I print the score, this is inside drawGame() function, whic is called in the draw() function

my best guess is that when you reference "numCandy" in candyCollisionCheck() it's making a variable in the object titled numCandy. you could check by creating the object, running the function, and then typing "candy1" (the name of the object) into the console and looking to see if it has that variable.

you can also use print() at different points in the code to see if anything isn't running when it should, like putting it in the distance check to see if it is actually going off

Thank you! I already fixed the score, but I think I might try your strategy since my code is very long and confusing, again thank you!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community