Discord
Login
Community
DARK THEME

Buttons not working

i have a shop and the buttons arent even spawning in! i have each button in a list and have them as an instanced object.

button = class
  constructor = function(x,y,width,height,n)
    this.x = x
    this.y = y
    this.width = width
    this.height = height
    this.id = n
  end
  update = function()
    print(this.id)
  end
  draw = function()
    screen.setDrawRotation(0)
    screen.drawSprite("s"+this.idit normall,this.x,this.y,this.width,this.height)
  end
end

it normally doesnt show, but if i edit the button code, I works for some reason? https://microstudio.dev/projects/asteroids/code/

We cannot access your project, it is under a link only you can access. To create a link we can access, go to "Publish" inside your project, click "Make Project Public", and then copy the link that appears below.

As far as your class goes, it seems to be correct. Please ensure that all end statements are placed properly.

I did make it public and i have no idea why you cant access it. maybe try this link? https://microstudio.dev/i/Stonx/asteroids/ im pretty sure the end statements are placed properly

It took me a while to find your error, but I eventually spotted it. You try to draw inside the update function. That will obviously not work. So I suggest that you clean up your code a bit, moving all the draw to the appropriate function and a few overall code optimizing. Nothing special just some empty spacer lines and descriptive functions.

And maybe utilize scenes and a scene manager, pretty simple actually.

ohhhhh thank you so much!

Post a reply

Progress

Status

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