Skip to content

Commit

Permalink
fix set_value
Browse files Browse the repository at this point in the history
Put form data values into data.__dict__, not data.data
Also, convert integers into ints, and handle errors if
a value that is supposed to be an integer can't be converted.
  • Loading branch information
tbird20d committed Sep 25, 2021
1 parent e33dabb commit 0bd8008
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions rg.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -2056,12 +2056,28 @@ If so, click on the link below to really reset the game:<br>

elif action == "set_values":
# set values from the form
for name in list(data.keys()):
log_this("in set_values")
html_start(data, user)
data.html_append("Set values for game from form data!!")

for name in data.keys():
if name in data.game_attr_list:
value = form[name].value
data[name] = value
data.html_append("Set values for game from form data!!")
if name in data.game_attr_ints:
log_this("settting %s=int(%s)" % (name, value))
try:
data.__dict__[name] = int(value)
except ValueError:
msg = "Invalid value '%s' for game data '%s' - expected integer" % (value, name)
log_this(msg)
data.add_error_message(msg)
else:
log_this("settting %s=%s" % (name, value))
data.__dict__[name] = (value)

#log_this("data.__dict__=%s" % data.__dict__)
write_game_data(data)
done = True

elif action == "undo":
data.suppress_refresh = True
Expand Down

0 comments on commit 0bd8008

Please sign in to comment.