This basically lets you set the value of a X and Y position on the screen and it automatically updating it, and I needed to make the field_[X & Y coordinates] variables global in order to use them in all the functions. The screen size variables work fine, but since it has many diffirent field_* variables which have diffirent names, I had to use eval, but this throws a syntax error.
The code and error message is located below:
Expand|Select|Wrap|Line Numbers
- from os import system
- def set_screen_size(x,y):
- global screen_x
- global screen_y
- screen_x = str(x)
- screen_y = str(y)
- system('mode con cols=' + screen_x + ' lines=' + screen_y)
- def set_field(x,y,val):
- global screen_x
- global screen_y
- x = str(x)
- y = str(y)
- val = val[0:1]
- if(x > screen_x or x < 0 or y > screen_y or x < 0):
- on_error('Field outside screen given. set_field('+x+','+y+','+val+')')
- eval('global field_' + x + y)
- eval('field_' + x + y + ' = ' + val)
- update_screen()
- def update_screen():
- global screen_x
- global screen_y
- for x in screen_x:
- line = ""
- for y in screen_y:
- eval('global field_' + x + y)
- eval('val = field_' + x + y)
- line = line + val
- print line
Expand|Select|Wrap|Line Numbers
- Traceback (most recent call last):
- File "G:\FieldScreen\fieldscreen.py", line 34, in <module>
- set_field(0,0,"H")
- File "G:\FieldScreen\fieldscreen.py", line 18, in set_field
- eval('global field_' + x + y)
- File "<string>", line 1
- global field_00
- ^
- SyntaxError: invalid syntax