←  Ask a Pro

ComputerCraft | Programmable Computers for Minecraft

»

Var A keeps increasing more than I want it to

oliverrook's Photo oliverrook 15 May 2020

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.
Quote

Lupus590's Photo Lupus590 17 May 2020

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

Dog's Photo Dog 17 May 2020

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.
Quote

Lupus590's Photo Lupus590 17 May 2020

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