Jump to content




Var A keeps increasing more than I want it to


3 replies to this topic

#1 oliverrook

  • New Members
  • 1 posts

Posted 15 May 2020 - 04:38 PM

My code is rather short, but I'll put it in a pastebin anyways.
I'm struggling to figure out what the problem here is.
I want to have a increase each time I press a button on the wall. I'm essentially building a combat minigame and want it to go to the next level each time I press the button, but whenever I press the button it just quits out entirely.
This is my code:
https://pastebin.com/bg5X5ycU
I put in some code to check what A is and what levels is, just to make sure I wasn't crazy, and for some reason, it outputs this:
7 (The value of "a")
3 (The value of "levels")

For the life of me, I can't figure out why it's outputting 7.

#2 Lupus590

  • Members
  • 2,011 posts
  • LocationUK

Posted 17 May 2020 - 04:20 PM

You probably need to pull redstone events somewhere as I think your code is responding to one button press multiple times.

#3 Dog

  • Members
  • 1,178 posts
  • LocationEarth orbit

Posted 17 May 2020 - 06:29 PM

You're manipulating 'a' in both the spawnThem function and startSimulation function - that *might* be why it's reaching 7 instead of being what you expect. You might want to use different variables in each function and see if that fixes the issue.

#4 Lupus590

  • Members
  • 2,011 posts
  • LocationUK

Posted 17 May 2020 - 07:39 PM

Also, using local variables might help: https://www.lua.org/pil/4.2.html





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users