quick and easy question

hi,

in much of my work objects call variables which are set externally, i.e. midi or osc. so if my midi controller isnt plugged in or max/msp aint running then i get errors such as “((variable whatever)) is not defined,” is their a simple way of giving these variables a default value of nothing until they are set without having to set them to 0 or whatever in a script that runs at the beginning only once…

thanks

will

hi,
I had the same problem.
and as far as i know creating an empty with a script that runs only once is ‘my’ only solution… can’t really see any other ways to do it.
I mean, variables need to be defined before code gets executed. :slight_smile:

Are these variables local or global?

If they’re global variables, you can use this python code:

if hasattr(GameLogic,"variablename"):

    if variablename == 1:

        do something...

This will check to see if a variable exists before doing anything.

Having an initialisation script with all your variables in is a useful thing to have. It’s something I use quite often, and it’s also useful as it acts as a reference for all the variables you use in the game too…

yeh thats what i thought was probably the case… i was thinking

variable = None

might set it up instead, but this doesnt seem to work, any guesses as to what is this used for( the None thing).

Cheers for the replies

Will