Bug #7336

Action 6 not working - bad offset

Added by The_Dude almost 3 years ago. Updated over 2 years ago.

Status:ClosedStart date:2014-12-06
Priority:UrgentDue date:
Assignee:-% Done:

100%

Category:-
Target version:-

Description

Hello,
I am using parameter in switch chain and it seems that resulting action 06 is compiled with bad offset in NML

I have this

switch(FEAT_INDUSTRIES, SELF, sw_power_station_location, [industry_distance(1, -1)]){
0..param3: string(STR_PLACEFAIL_TOOCLOSE);
default: CB_RESULT_LOCATION_ALLOW;
}

and it produces this in nfo

06 03 04 FF 21 00 FF
02 0A FF 89 1A 20 FF FF FF FF 0E 1A 20 00 01 00 00 0F 67 01 00 FF FF 00 00 01 00 80 00 00 00 00 00 [00 00 00 00] 84

If you count the 0x21 bytes it will rewrite the bytes marked with brackets, but it should be one byte left.

When I altered NFO and compiled with grfcodec, it worked as intended.

action6.grf - nmlc's grf output (182 Bytes) planetmaker, 2014-12-08 12:46

action6.nfo - nmlc's nfo output (1.18 KB) planetmaker, 2014-12-08 12:46

action6.nml - nml source (275 Bytes) planetmaker, 2014-12-08 12:46

grfcodec_action6.nfo - grf file de-compiled with grfcodec (879 Bytes) planetmaker, 2014-12-08 12:46

Associated revisions

Revision 2294:6e80c055eb78
Added by frosch over 2 years ago

Fix #7336: Action 6 offset was off by one for VA2 ranges when using a list of expressions in a switch.

History

#1 Updated by The_Dude almost 3 years ago

for better ilusttaion, rewrite happens from 33 (21h), but should be 32

byte count  00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
sprite      02 0A FF 89 1A 20 FF FF FF FF 0E 1A 20 00 01 00 00 0F 67 01 00 FF FF 00 00 01 00 80 00 00 00 00 00 00 00 00 00 84

#2 Updated by planetmaker almost 3 years ago

I don't follow, the attached test case seems to work fine, rewrite exactly from byte 0x20 onward. Please provide full test case which gives different result. Also state the NML version you use (it should be 0.3.1 or newer).

byte        00 01 02 03 04 05-09          0A    0B 0C 0D 0E 0F 10    11 12 13 14 15 16 17 18 19  1A 1B   1C 1D 1E 1F 20 21 22 23 24 25
grf: 1 * 38 02 0A FF 89 1A " ÿÿÿÿ"        \2sto 1A 20 00 01 00 00 \2rst 67 01 00 FF FF 00 00 01  01 84   00 00 00 00 00 00 00 00 00 84
nfo: 1 * 38 02 0A FF 89 1A 20 \dxFFFFFFFF \2sto 1A 20 \dx00000100 \2r   67 01 00 \dx0000FFFF \b1 \wx8401 \dx00000000 \dx00000000 \wx8400

#3 Updated by The_Dude almost 3 years ago

Hm, interesting. After a moment of tryouts I found out that it compiles differently when there are brackets in the switch []

if you replace this line in your example nml

switch(FEAT_INDUSTRIES, SELF, sw_power_station_location, industry_distance(1, -1))

to this line

switch(FEAT_INDUSTRIES, SELF, sw_power_station_location, [industry_distance(1, -1)]){

it will be one byte wrong.

No idea why, I don't see any documentation about that. There are examples that use switch with and without square brackets at WIKI, so now, is it some bug or did I miss anything?

#4 Updated by planetmaker almost 3 years ago

Interesting. That looks like a bug indeed.

Generally, you do not need to put the variable of a switch into parenthesis - unless you want to preceed it by other operations, e.g. manipulation of temporary or permanent storage.

#5 Updated by planetmaker almost 3 years ago

  • Priority changed from High to Urgent
  • Status changed from New to Confirmed

#6 Updated by The_Dude almost 3 years ago

Ok, I'd like to give a thought about this, if I may.

Why not use special variable 7F for accessing parametres in varAction2 chain instead of action6?
It can be used at least in some cases, e.g. industry chains.

#7 Updated by frosch over 2 years ago

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

Applied in changeset 6e80c055eb78.

Also available in: Atom PDF