Bug #6996

Compilation error when using 'signal_on_traffic_side' in a switch

Added by arikover about 3 years ago. Updated about 3 years ago.

Status:ClosedStart date:2014-07-23
Priority:NormalDue date:
Assignee:-% Done:

100%

Category:-
Target version:-

Description

This bug occured when using nmlc version 0.4.0 r5292:275191ccda7e.

I needed a FEAT_RAILTYPE switch that tested the 'signal_on_traffic_side' variable (in order to change semaphores graphics accordingly). But when compiling, I always get an error:

'nmlc ERROR: Division and modulo require the right hand side to be nonzero.'

which is weird considering that I use neither a division nor a modulo (just testing whether the variable == 0, see attached file)

If I change the tested variable to 'traffic_side', the compilation works fine (although the switch still doesn't work properly, but that's another problem, I guess)

I managed to reproduce the bug with the attached 'try.nml' file.

try.zip (1.96 KB) arikover, 2014-07-23 22:37

Associated revisions

Revision 2204:da0212b585b6
Added by frosch about 3 years ago

Fix #6996: Patch flags can only be accessed via action 7/9.

History

#1 Updated by planetmaker about 3 years ago

planetmaker@localhost:~/ottd/grfdev/tmp/try$ nmlc -s try.nml
nmlc ERROR: Division and modulo require the right hand side to be nonzero.
Traceback (most recent call last):
File "/home/planetmaker/bin/nmlc", line 6, in <module>
main.run()
File "/home/planetmaker/ottd/grfdev/nml/nml/main.py", line 342, in run
main(sys.argv[1:])
File "/home/planetmaker/ottd/grfdev/nml/nml/main.py", line 161, in main
ret = nml(input, input_filename, opts.debug, outputs, opts.start_sprite_num, opts.forced_palette, opts.md5_filename)
File "/home/planetmaker/ottd/grfdev/nml/nml/main.py", line 220, in nml
tmp_actions = result.get_action_list()
File "/home/planetmaker/ottd/grfdev/nml/nml/ast/base_statement.py", line 154, in get_action_list
action_list.extend(stmt.get_action_list())
File "/home/planetmaker/ottd/grfdev/nml/nml/ast/switch.py", line 69, in get_action_list
return action2var.parse_varaction2(self)
File "/home/planetmaker/ottd/grfdev/nml/nml/actions/action2var.py", line 981, in parse_varaction2
parser.parse_expr(expr)
File "/home/planetmaker/ottd/grfdev/nml/nml/actions/action2var.py", line 588, in parse_expr
self.parse(expr)
File "/home/planetmaker/ottd/grfdev/nml/nml/actions/action2var.py", line 625, in parse
self.parse_binop(expr)
File "/home/planetmaker/ottd/grfdev/nml/nml/actions/action2var.py", line 538, in parse_binop
self.parse(expr.expr1)
File "/home/planetmaker/ottd/grfdev/nml/nml/actions/action2var.py", line 625, in parse
self.parse_binop(expr)
File "/home/planetmaker/ottd/grfdev/nml/nml/actions/action2var.py", line 538, in parse_binop
self.parse(expr.expr1)
File "/home/planetmaker/ottd/grfdev/nml/nml/actions/action2var.py", line 597, in parse
expr = self.preprocess_binop(expr)
File "/home/planetmaker/ottd/grfdev/nml/nml/actions/action2var.py", line 382, in preprocess_binop
return expr.reduce()
File "/home/planetmaker/ottd/grfdev/nml/nml/expression/binop.py", line 72, in reduce
expr1 = self.expr1.reduce(id_dicts)
File "/home/planetmaker/ottd/grfdev/nml/nml/expression/binop.py", line 77, in reduce
self.op.validate_func(expr1, expr2, self.pos)
File "/home/planetmaker/ottd/grfdev/nml/nml/nmlop.py", line 119, in validate_func_div_mod
raise generic.ScriptError("Division and modulo require the right hand side to be nonzero.", pos)
nml.generic.ScriptError: Division and modulo require the right hand side to be nonzero.

#2 Updated by Alberth about 3 years ago

The 'signal_on_traffic_side' gets resolved to "hasbit: expr1=param133, expr2=59". This seems to be 85 http://newgrf-specs.tt-wiki.net/wiki/GlobalVariables, specifically bit 59 (3B) of http://newgrf-specs.tt-wiki.net/wiki/TTDPatchFlags which is very interesting, given that the global variable is just 1 byte wide.

NML convert bit 59 to value 0, with the pow2 function, in nml/actions/action2var, line 301, which is designed for 32 bit length, it seems.

#4 Updated by frosch about 3 years ago

  • % Done changed from 0 to 100
  • Status changed from New to Closed

Applied in changeset da0212b585b6.

Also available in: Atom PDF