Bug #4293

Arithmetic with sprite labels

Added by dnicholls almost 7 years ago. Updated almost 7 years ago.

Status:ReopenedStart date:2012-09-28
Priority:NormalDue date:
Assignee:-% Done:

100%

Category:-
Target version:-

Description

Before r1919 it was possible to specify which sprite to use from a spriteset by calculating it as the offset from a given sprite label in that spriteset:

spriteset (small_warehouse_1_gfx, "emptySprite.png") { 
spr1   : [ 10, 10, 1, 1, 0, 0]
spr2   : [ 10, 10, 1, 1, 0, 0]
}

spritelayout sl_small_warehouse_1 {
    ground { sprite: GROUNDSPRITE_CONCRETE; }
    building { sprite: small_warehouse_1_gfx( spr1 + (view == 1 ? spr2 - spr1 : 0)); }
}

I've never seen this behaviour documented anywhere so I don't know if it's supported, but it is very useful for defining a large number of appearances with a small amount of code. However since r1919 I get the error

nmlc ERROR: "somefilename.nml", line 20: Unrecognized identifier 'spr1' encountered

I've attached a minimal test case.

nmlc_sprite_label_test.zip (2.05 KB) dnicholls, 2012-09-28 07:36

History

#1 Updated by yexo almost 7 years ago

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

Fixed in r2043, sorry about the long delay before you got a reaction.

#2 Updated by dnicholls almost 7 years ago

  • Status changed from Closed to Reopened

Thank you Yexo. Unfortunately it's not fully resolved (ok to reopen?)

Followup: calculations using sprite labels and variables now don't throw an error except when using a LOAD_TEMP() function.

Relevant code

spriteset (small_warehouse_1_gfx, "emptySprite.png") { 
spr1   : [ 10, 10, 1, 1, 0, 0]
spr2   : [ 10, 10, 1, 1, 0, 0]
spr3   : [ 10, 10, 1, 1, 0, 0]
}

// nmlc <= r1918 will happily parse this entire block without errors
spritelayout sl_small_warehouse_1 {
    ground { sprite: GROUNDSPRITE_CONCRETE; }
    building { sprite: 
    small_warehouse_1_gfx(  spr1              // nmlc r1919..2042 will fail here >>> [Unrecognized identifier 'spr1' encountered]
    + (view == 1          ? spr2 - spr1 : 0)  // nmlc >= r2043 is ok with this line
    +  LOAD_TEMP(0)                           // nmlc >= r2043 is ok with this line
    + (LOAD_TEMP(0) == 10 ? spr3 - spr1 : 0)  // nmlc >= r2043 will fail here    >>> [Unrecognized identifier 'spr3' encountered]
    ); 
    }
}

Also available in: Atom PDF