-1

Alright, I'm completely changing this post- I realized that I did it wrong.

Global isn't working in def- I can print a variable, but when I try to change THE SAME VARIABLE, (Example: Test = Test + 1), it dosen't work. I've been redirected to the 'global' fix, it dosen't work.

Look at this screenshot to understand my frustration https://i.stack.imgur.com/ZCJIv.png

So here's what I need to solve; How do I make it so I can manipulate the 'Health' variable?

Gregory
  • 1
  • 5

1 Answers1

1

In order to use a global variable, you have to note that it's global inside the scope where you're using it:

Hello = 4
Hello2 = 2

def SomeLogicThing():
    global Hello
    global Hello2
    if Hello2 == 2:
        Hello = Hello + 1

(Also, note that Hello + 1 doesn't do anything on its own, it's just an expression. You have to include an assignment for it to change the value, or use the += operator.)

Amber
  • 507,862
  • 82
  • 626
  • 550