Code problem (2.7)...
Displaying 1-6 of 6 total.
1
ashground
|
Here's my problem (with simplified code):
weather=0
def w_Rain():
if weather==1:
w_Rain_kill()
weather=1
HookRetrace(w_Rain_hook)
What I'm trying to do should be fairly obvious... it starts raining when the function is called the first time, it stops when it's called again. The problem is, the IF statement is checking 'weather' as a local variable and not a global... so the function doesn't compile (the variable is tested before it is created). How can I get it so that 'weather' works globally?
Posted on 2001-08-08 03:05:59
|
ashground
|
nt
Posted on 2001-08-08 03:08:47
|
andy
|
Here's my version:
weather=0
def w_Rain():
global weather
if weather==1:
UnhookRetrace(w_Rain_hook)
weather=0
else:
HookRetrace(w_Rain_hook)
weather=1
The global directive (I'm not sure exactly what it *really* is, so I'll call it a directive) explicitly tells the interpreter to treat that label as a global. That should solve your problems. :)
"Ignorance is its own reward" -- Proverb
Posted on 2001-08-08 09:16:25
|
ashground
|
This might sound really stupid... I've gone through the Python tutorial on python.org, but... how do you generate a random number?
Posted on 2001-08-08 14:57:14
|
ashground
|
(sigh) More questions...
1. How do you make something translucent? In V2, it was SetLucent(1), then SetLucent(0)... is there an equivilant in 2.7? I know it'll be different, because there's no transparency table, but...
2. How do you unpress a key? My menu system is terribly hard to control because the pointer moves at a billion miles per hour... I tried passing 'input.left=0', but it didn't work.
Posted on 2001-08-08 18:45:44
|
andy
|
v2.7 doesn't have a way of setting an image to arbitrary levels of translucency yet. You can, however, simply add the alpha channel to the image directly. All nonopaque blits will use that information to properly blend the colours.
2) input.SetButton(blah,0)
0 - up
1 - down
2 - left
3 - right
4 - enter
5 - ESC
(these are all alterable through Python, by the way, with input.BindKey)
"Ignorance is its own reward" -- Proverb
Posted on 2001-08-08 21:39:02
|