#๐Ÿ”’ variable defined in "if" not available in "else"

22 messages ยท Page 1 of 1 (latest)

gilded palmBOT
#

@languid delta

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

hard moss
#
x = 5
if True:
    x = 42
else:
    x = 0
#

you can define it first and then use it in the condition

languid delta
#

i need it to be constantly updated every frame

#

im using pygame

lapis plinth
#

it will be updated, if you reassign the correct value to it when you want to update

languid delta
languid delta
languid delta
#

ahhhh okay thanks a lot

lapis plinth
#

and since it is inside a while loop

#

everytime the loop runs

#

it gets updated

languid delta
#

and it doesnt matter if i define it within or outside of the while loop, right? as long as its outside the if statement

#

nvm stupid question hahahah

lapis plinth
#

variables defined in an if statement, stay in the IF statement block

#

as far as I know

languid delta
#

okay thanks, it worked

#

!close

gilded palmBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.