Skip to content

Commit 089f7af

Browse files
committed
Variables used in chase variables are bound to that variable. Close #1.
1 parent 6fa86b9 commit 089f7af

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

Examples/chase.owpy

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Rule "Chase Test"
2+
Actions
3+
pvar chase_var = 100
4+
Chase Global Variable At Rate
5+
Variable: pvar chase_var
6+
Destination: 0
7+
Rate: -1
8+
Reevaluation: Destination And Rate
9+
Set Move Speed(Event Player, pvar chase_var)

OWScript/Transpiler.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ def visitOWID(self, node, scope):
246246
constgen = self.global_varconst if type(child) == GlobalVar else self.player_varconst
247247
try:
248248
varconst = next(constgen)
249-
self.varconsts[child.name] = Raw(code=varconst)
250249
if type(child) == GlobalVar:
251250
code = 'Set Global Variable({}, {});\n'.format(varconst, self.visit(child, scope)) + code
252251
else:
253-
code = 'Set Player Variable({}, {}, {});\n'.format(self.visit(child.player, varconst, self.visit(child, scope))) + code
252+
code = 'Set Player Variable({}, {}, {});\n'.format(self.visit(child.player, scope), varconst, self.visit(child, scope)) + code
253+
self.varconsts[child.name] = Raw(code=varconst)
254254
except StopIteration:
255255
raise Errors.InvalidParameter('Exceeded maximum number of chase variables (25) for this type.', pos=child._pos)
256256
node.children[index] = self.varconsts[child.name]
@@ -447,6 +447,9 @@ def visitUnaryOp(self, node, scope):
447447

448448
def visitGlobalVar(self, node, scope):
449449
name = node.name
450+
if name in self.varconsts:
451+
varconst = self.visit(self.varconsts.get(name), scope)
452+
return 'Global Variable({})'.format(varconst)
450453
var = scope.get(name)
451454
if not var:
452455
raise Errors.NameError('\'{}\' is undefined'.format(node.name[5:]), pos=node._pos)
@@ -462,14 +465,18 @@ def visitGlobalVar(self, node, scope):
462465

463466
def visitPlayerVar(self, node, scope):
464467
name = node.name
468+
player = self.visit(node.player, scope)
469+
if name in self.varconsts:
470+
varconst = self.visit(self.varconsts.get(name), scope)
471+
return 'Player Variable({}, {})'.format(player, varconst)
465472
var = scope.get(name)
466473
if not var:
467474
raise Errors.NameError('pvar \'{}\' is undefined'.format(node.name[5:]), pos=node._pos)
468475
elif type(var) != Variable:
469476
return self.visit(var, scope)
470477
elif type(var.value) == String:
471478
return var.value.value
472-
code = 'Value In Array(Player Variable({}, A), {})'.format(self.visit(node.player, scope), var.index)
479+
code = 'Value In Array(Player Variable({}, A), {})'.format(player, var.index)
473480
return code
474481

475482
def visitString(self, node, scope):

Roadmap.md

-3
This file was deleted.

0 commit comments

Comments
 (0)