Skip to content

Commit

Permalink
Display a message when trying to set a variable that wasn't in the
Browse files Browse the repository at this point in the history
script.

Remove debug in json parsing.
  • Loading branch information
stuaxo committed May 4, 2018
1 parent 658e1be commit 52c72c2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
9 changes: 6 additions & 3 deletions shoebot/data/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@

DEFAULT_STEPS = 256.0


def clamp(minvalue, value, maxvalue):
return max(minvalue, min(value, maxvalue))


class Variable(object):
'''Taken from Nodebox'''

def __init__(self, name, type, **kwargs):
"""
:param name: Name of variable
Expand All @@ -26,7 +29,7 @@ def __init__(self, name, type, **kwargs):
if not isinstance(name, basestring):
raise AttributeError("Variable name must be a string")
if kwargs.get("step") and kwargs.get("steps"):
raise AttributeError("Can only set step or steps") # TODO - is this too strict
raise AttributeError("Can only set step or steps") # TODO - is this too strict
self.type = type or NUMBER
self.min = None
self.max = None
Expand Down Expand Up @@ -85,5 +88,5 @@ def compliesTo(self, v):
return False

def __repr__(self):
return "Variable(name=%s, type=%s, default=%s, min=%s, max=%s, value=%s)" % (self.name, self.type, self.default, self.min, self.max, self.value)

return "Variable(name=%s, type=%s, default=%s, min=%s, max=%s, value=%s)" % \
(self.name, self.type, self.default, self.min, self.max, self.value)
4 changes: 3 additions & 1 deletion shoebot/gui/var_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def add_variables(self):
:param container:
:return:
"""
for v in sorted(self.bot._vars.values()):
for k, v in self.bot._vars.items():
if not hasattr(v, 'type'):
raise AttributeError('%s is not a Shoebot Variable - see https://shoebot.readthedocs.io/en/latest/commands.html#dynamic-variables' % k)
self.add_variable(v)

def add_variable(self, v):
Expand Down
9 changes: 1 addition & 8 deletions shoebot/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,9 @@


def json_arg(s):
#s = s.strip()
if s.startswith("{"):
# enclose in quotes
s = "'%s'" % s

print '...'
print '>>%s<<' % s
try:
import json
d = json.loads(s, parse_float=True, parse_int=True)
d = json.loads(s)
return d
except Exception as e:
error(_('Error parsing JSON, remember single quotes OUTSIDE, double QUOTES inside.'))
Expand Down

0 comments on commit 52c72c2

Please sign in to comment.