Many NML questions

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

Tony Pixel
Route Supervisor
Route Supervisor
Posts: 459
Joined: 14 Oct 2017 11:06
Location: Ukraine

Many NML questions

Post by Tony Pixel »

Hello, everybody.
I living at TT-Forums ~ 9 months and established himself as a good artist. Also I want to learn NML train coding, and (If You know) I'm russian, so it's harder to study it. If anyone can make some parody of a guide please write here, I'll be grateful.
Last edited by Tony Pixel on 21 May 2018 16:39, edited 1 time in total.
Image Image
Sprite artist and NewGRF developer, coding in NML. My projects:
NewGRFs: Not Enough Subways Set | North American Passenger Railroads | Elevated Subway Bridge | Tony Pixel's Subway Equipment Set (frozen)
Screenshots: New York City Subway Episodes
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: Another guy which learns NML

Post by Erato »

https://www.tt-wiki.net/wiki/NMLTutorial
I recommend doing everything from the start, all the way up to and including "Four part refit" under "Railtypetable block". Also don't cut corners, that'll get you into trouble. This tutorial is about as well written as it'll get.
I used this when I started learning NML. It doesn't take too long at all if you just follow the steps in the tutorial.

Good luck!
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

Re: Another guy which learns NML

Post by acs121 »

I was going to post the same thing.
Remember that NML can only be used to code vehicles (IIRC it can also code ships and aircraft), objects and industries.
Tony Pixel
Route Supervisor
Route Supervisor
Posts: 459
Joined: 14 Oct 2017 11:06
Location: Ukraine

Re: Another guy which learns NML

Post by Tony Pixel »

Thanks, I reading it now. But I have one trouble: when I want to compile NML file error goes:
1.png
1.png (1.47 KiB) Viewed 807 times
I tried to change to UTF-8 all english.lang in both dir's (OYYD and NML), but anything goes.
Image Image
Sprite artist and NewGRF developer, coding in NML. My projects:
NewGRFs: Not Enough Subways Set | North American Passenger Railroads | Elevated Subway Bridge | Tony Pixel's Subway Equipment Set (frozen)
Screenshots: New York City Subway Episodes
Tony Pixel
Route Supervisor
Route Supervisor
Posts: 459
Joined: 14 Oct 2017 11:06
Location: Ukraine

Re: Another guy which learns NML

Post by Tony Pixel »

What about language files? Can I simply copy it from OpenTTD, or every time when I create STR_... I should write this STR with unique code in my lang file?
Image Image
Sprite artist and NewGRF developer, coding in NML. My projects:
NewGRFs: Not Enough Subways Set | North American Passenger Railroads | Elevated Subway Bridge | Tony Pixel's Subway Equipment Set (frozen)
Screenshots: New York City Subway Episodes
Tony Pixel
Route Supervisor
Route Supervisor
Posts: 459
Joined: 14 Oct 2017 11:06
Location: Ukraine

Re: Another guy which learns NML

Post by Tony Pixel »

Oh god, thanks/ I was stupid idiot :lol: when threreat started reading Tutorial in middle of it. Now I started understand everything what I read.
Image Image
Sprite artist and NewGRF developer, coding in NML. My projects:
NewGRFs: Not Enough Subways Set | North American Passenger Railroads | Elevated Subway Bridge | Tony Pixel's Subway Equipment Set (frozen)
Screenshots: New York City Subway Episodes
Tony Pixel
Route Supervisor
Route Supervisor
Posts: 459
Joined: 14 Oct 2017 11:06
Location: Ukraine

Re: Another guy which learns NML

Post by Tony Pixel »

New question: how to make what GRF used with (russian) language in game will show (russian) strings? Can I simply create new lang file with the same strings and russian language ID?
Image Image
Sprite artist and NewGRF developer, coding in NML. My projects:
NewGRFs: Not Enough Subways Set | North American Passenger Railroads | Elevated Subway Bridge | Tony Pixel's Subway Equipment Set (frozen)
Screenshots: New York City Subway Episodes
User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

Re: Another guy which learns NML

Post by acs121 »

Tony Pixel wrote:New question: how to make what GRF used with (russian) language in game will show (russian) strings? Can I simply create new lang file with the same strings and russian language ID?
Actually i think you can insert both latin letters and cyrilic letters. If this wasn't possible, then there couldn't be any russian translations on openttdcoop translator :wink:
Eddi
Tycoon
Tycoon
Posts: 8257
Joined: 17 Jan 2007 00:14

Re: Another guy which learns NML

Post by Eddi »

yes, just make a new .lng file next to english.lng with the appropriate IDs in it, then nmlc should pick it up when compiling the GRF. file should be in UTF8 format
Tony Pixel
Route Supervisor
Route Supervisor
Posts: 459
Joined: 14 Oct 2017 11:06
Location: Ukraine

Re: Another guy which learns NML

Post by Tony Pixel »

Ok, next question: how to use "getbits" function for the different sprites in GUI and game?
Image Image
Sprite artist and NewGRF developer, coding in NML. My projects:
NewGRFs: Not Enough Subways Set | North American Passenger Railroads | Elevated Subway Bridge | Tony Pixel's Subway Equipment Set (frozen)
Screenshots: New York City Subway Episodes
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5601
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Another guy which learns NML

Post by PikkaBird »

Tony Pixel wrote:Ok, next question: how to use "getbits" function for the different sprites in GUI and game?
To tease this out a bit further, Tony is talking about using extra_callback_info1 to draw different sprites in the GUI, but I'm not sure what his difficulty is; it's just like any other switch.

Perhaps he could post his code that doesn't work, and someone can point out what he's doing wrong?
Tony Pixel
Route Supervisor
Route Supervisor
Posts: 459
Joined: 14 Oct 2017 11:06
Location: Ukraine

Re: Another guy which learns NML

Post by Tony Pixel »

Thanks.
Image Image
Sprite artist and NewGRF developer, coding in NML. My projects:
NewGRFs: Not Enough Subways Set | North American Passenger Railroads | Elevated Subway Bridge | Tony Pixel's Subway Equipment Set (frozen)
Screenshots: New York City Subway Episodes
Tony Pixel
Route Supervisor
Route Supervisor
Posts: 459
Joined: 14 Oct 2017 11:06
Location: Ukraine

Re: Another guy which learns NML

Post by Tony Pixel »

PikkaBird wrote:
Tony Pixel wrote:Ok, next question: how to use "getbits" function for the different sprites in GUI and game?
To tease this out a bit further, Tony is talking about using extra_callback_info1 to draw different sprites in the GUI, but I'm not sure what his difficulty is; it's just like any other switch.

Perhaps he could post his code that doesn't work, and someone can point out what he's doing wrong?
So, I know not NML wery well becouse didn't worked with python and learned it by the tutorial. Here is the code:

Code: Select all

//--------------------------------------------------------------------------------------------------SPV-2000
spriteset (spriteset_purchase_SPV2000, "gfx/USA_SPV-2000.png") { [4,  35,  87,  13,  5,  -6] }

template tmpl_SPV2000(x,y) {	
  [x,      y,    8,     24,     -3,    -10]
	[x+9,    y,    22,    20,     -14,   -11]                  
	[x+32,   y,    32,    16,     -16,   -10]  
	[x+65,   y,    22,    20,     -8,    -12]
} 

spriteset (spriteset_SPV2000, "gfx/USA_SPV-2000.png")   { tmpl_SPV2000(4,4) tmpl_SPV2000(92,4) }

item (FEAT_TRAINS, item_SPV2000) {                                                                      
  property {
    name:                         string(STR_SPV2000_Name);                                                
    climates_available:           bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL); 
    introduction_date:            date(1978, 1, 6);      
    model_life:                   VEHICLE_NEVER_EXPIRES;                                             
    vehicle_life:                 30;                                                                               
    reliability_decay:            14;                                                                               
    refittable_cargo_classes:     bitmask(CC_PASSENGERS);                                                          
    non_refittable_cargo_classes: bitmask();
    loading_speed:                10; 
    cost_factor:                  35;                                                                           
    running_cost_factor:          20;                                                                             
    sprite_id:                    SPRITE_ID_NEW_TRAIN;        
    speed:                        140 km/h;                                                         
    misc_flags:                   bitmask(TRAIN_FLAG_MU);
    refit_cost:                   0;  
    track_type:                   RAIL;                                                                          
    ai_special_flag:              AI_FLAG_PASSENGER;
    power:                        270 kW;                                                                            
    running_cost_base:            RUNNING_COST_ELECTRIC;                                                             
    dual_headed:                  0;
    cargo_capacity:               109;                                                                            
    weight:                       58 ton;                                                                        
    ai_engine_rank:               0;                                                                                 
    engine_class:                 ENGINE_CLASS_DIESEL;
    extra_power_per_wagon:        15 kW;                                                                         
    tractive_effort_coefficient:  0.3;
    air_drag_coefficient:         0.06;    
    visual_effect_and_powered:    visual_effect_and_powered(VISUAL_EFFECT_DIESEL, 0, DISABLE_WAGON_POWER);
    extra_weight_per_wagon:       40 ton;
    bitmask_vehicle_info:         0;
    }
    graphics {
        purchase:                spriteset_purchase_SPV2000; //Purchase menu sprite                    
        additional_text:         return string(STR_SPV2000_Desc); //Additional text shown in purchase list    
        purchase_cargo_capacity: spriteset_purchase_SPV2000;                                                
        length:                  8;
        default:                 getbits(extra_callback_info1, 0, 8);                                                       
    }
}
Image Image
Sprite artist and NewGRF developer, coding in NML. My projects:
NewGRFs: Not Enough Subways Set | North American Passenger Railroads | Elevated Subway Bridge | Tony Pixel's Subway Equipment Set (frozen)
Screenshots: New York City Subway Episodes
Eddi
Tycoon
Tycoon
Posts: 8257
Joined: 17 Jan 2007 00:14

Re: Another guy which learns NML

Post by Eddi »

ok, i didn't quite understand what you meant to do, but try something like this:

Code: Select all

switch(FEAT_TRAINS, SELF, guiswitch, getbits(extra_callback_info1, 0, 8)) {
  0x00: defaultsprite;
  0x10: guisprite1;
  0x11: guisprite2;
  ...
}

...

item{
  ...
  graphics {
    ...
    default: guiswitch;
  }
}
Tony Pixel
Route Supervisor
Route Supervisor
Posts: 459
Joined: 14 Oct 2017 11:06
Location: Ukraine

Re: Another guy which learns NML

Post by Tony Pixel »

Eddi wrote:ok, i didn't quite understand what you meant to do, but try something like this:

Code: Select all

switch(FEAT_TRAINS, SELF, guiswitch, getbits(extra_callback_info1, 0, 8)) {
  0x00: defaultsprite;
  0x10: guisprite1;
  0x11: guisprite2;
  ...
}

...

item{
  ...
  graphics {
    ...
    default: guiswitch;
  }
}
Oh, thanks :bow:
Image Image
Sprite artist and NewGRF developer, coding in NML. My projects:
NewGRFs: Not Enough Subways Set | North American Passenger Railroads | Elevated Subway Bridge | Tony Pixel's Subway Equipment Set (frozen)
Screenshots: New York City Subway Episodes
Tony Pixel
Route Supervisor
Route Supervisor
Posts: 459
Joined: 14 Oct 2017 11:06
Location: Ukraine

Re: Another guy which learns NML

Post by Tony Pixel »

So, I created code, but nmlc says what 1 sprite is orphaned, which and why?
[+] Spoiler

Code: Select all

template tmpl_Amfleet(x,y) {
  [x,      y,    8,     24,     -3,    -10]
	[x+9,    y,    22,    20,     -14,   -11]                  
	[x+32,   y,    32,    16,     -16,   -12]  
	[x+65,   y,    22,    20,     -8,    -11]
} 

spriteset (spriteset_Amfleet_Coach,"gfx/USA_Amtrak_Amfleet.png") { tmpl_Amfleet(4,4) tmpl_Amfleet(92,4) }
spriteset (spriteset_Amfleet_Coach_depot,"gfx/USA_Amtrak_Amfleet.png") { [36,  4,   32,   16,   -16,  -10] }
spriteset (spriteset_Amfleet_Coach_purchase,"gfx/USA_Amtrak_Amfleet.png") { [4,   66,   87,   13,   5,   -6] }

spriteset (spriteset_Amfleet_Cafe,"gfx/USA_Amtrak_Amfleet.png") { tmpl_Amfleet(4,35) tmpl_Amfleet(92,35) }
spriteset (spriteset_Amfleet_Cafe_depot,"gfx/USA_Amtrak_Amfleet.png") { [36,  35,   32,   16,   -16,  -10] }
spriteset (spriteset_Amfleet_Cafe_purchase,"gfx/USA_Amtrak_Amfleet.png") { [92,   66,   87,   13,   5,   -6] }

switch(FEAT_TRAINS, SELF, sw_Amfleet_Coach_gui, getbits(extra_callback_info1, 0, 8) ) {
  0x00:  spriteset_Amfleet_Coach;
  spriteset_Amfleet_Coach_depot;
}

item (FEAT_TRAINS, item_Amfleet_Coach) {                                                                      
  property {
    name:                         string(STR_Amfleet_Coach_Name);                                                
    climates_available:           bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL); 
    introduction_date:            date(1975, 1, 6);      
    model_life:                   VEHICLE_NEVER_EXPIRES;                                             
    vehicle_life:                 20;                                                                                     
    refittable_cargo_classes:     bitmask(CC_PASSENGERS);                                                          
    non_refittable_cargo_classes: bitmask();
    loading_speed:                13; 
    cost_factor:                  25;                                                                           
    running_cost_factor:          1;                                                                             
    sprite_id:                    SPRITE_ID_NEW_TRAIN;        
    speed:                        201 km/h;                                                         
    misc_flags:                   bitmask();
    refit_cost:                   0;  
    track_type:                   RAIL;                                                                          
    ai_special_flag:              AI_FLAG_PASSENGER;
    power:                        0;                                                                                                                                     
    cargo_capacity:               84;                                                                            
    weight:                       49 ton;                                                                        
    ai_engine_rank:               0;                                                                                                                                                          
    tractive_effort_coefficient:  0.3;
    air_drag_coefficient:         0.06;    
    visual_effect_and_powered:    visual_effect_and_powered(VISUAL_EFFECT_DISABLE, 0, DISABLE_WAGON_POWER);
    extra_weight_per_wagon:       40 ton;
    bitmask_vehicle_info:         0;
    }
    graphics {
        purchase:                spriteset_Amfleet_Coach_purchase;               
        additional_text:         return string(STR_Amfleet_Coach_Desc);                                               
        length:                  8;
        default:                 sw_Amfleet_Coach_gui;                                                       
    }
}

switch(FEAT_TRAINS, SELF, sw_Amfleet_Cafe_gui, getbits(extra_callback_info1, 0, 8) ) {
  0x00:  spriteset_Amfleet_Cafe;
  spriteset_Amfleet_Cafe_depot;
}

item (FEAT_TRAINS, item_Amfleet_Cafe) {                                                                      
  property {
    name:                         string(STR_Amfleet_Cafe_Name);                                                
    climates_available:           bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL); 
    introduction_date:            date(1975, 1, 6);      
    model_life:                   VEHICLE_NEVER_EXPIRES;                                             
    vehicle_life:                 20;                                                                                     
    refittable_cargo_classes:     bitmask(CC_PASSENGERS);                                                          
    non_refittable_cargo_classes: bitmask();
    loading_speed:                13; 
    cost_factor:                  24;                                                                           
    running_cost_factor:          1;                                                                             
    sprite_id:                    SPRITE_ID_NEW_TRAIN;        
    speed:                        201 km/h;                                                         
    misc_flags:                   bitmask();
    refit_cost:                   0;  
    track_type:                   RAIL;                                                                          
    ai_special_flag:              AI_FLAG_PASSENGER;
    power:                        0;                                                                                                                                     
    cargo_capacity:               32;                                                                            
    weight:                       49 ton;                                                                        
    ai_engine_rank:               0;                                                                                                                                                          
    tractive_effort_coefficient:  0.3;
    air_drag_coefficient:         0.06;    
    visual_effect_and_powered:    visual_effect_and_powered(VISUAL_EFFECT_DISABLE, 0, DISABLE_WAGON_POWER);
    extra_weight_per_wagon:       40 ton;
    bitmask_vehicle_info:         0;
    }
    graphics {
        purchase:                spriteset_Amfleet_Cafe_purchase;               
        additional_text:         return string(STR_Amfleet_Cafe_Desc);                                                
        length:                  8;
        default:                 sw_Amfleet_Cafe_gui;                                                       
    }
}
Image Image
Sprite artist and NewGRF developer, coding in NML. My projects:
NewGRFs: Not Enough Subways Set | North American Passenger Railroads | Elevated Subway Bridge | Tony Pixel's Subway Equipment Set (frozen)
Screenshots: New York City Subway Episodes
User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

Re: Another guy which learns NML

Post by acs121 »

Tony Pixel wrote:So, I created code, but nmlc says what 1 sprite is orphaned, which and why?
[+] Spoiler

Code: Select all

template tmpl_Amfleet(x,y) {
  [x,      y,    8,     24,     -3,    -10]
	[x+9,    y,    22,    20,     -14,   -11]                  
	[x+32,   y,    32,    16,     -16,   -12]  
	[x+65,   y,    22,    20,     -8,    -11]
} 

spriteset (spriteset_Amfleet_Coach,"gfx/USA_Amtrak_Amfleet.png") { tmpl_Amfleet(4,4) tmpl_Amfleet(92,4) }
spriteset (spriteset_Amfleet_Coach_depot,"gfx/USA_Amtrak_Amfleet.png") { [36,  4,   32,   16,   -16,  -10] }
spriteset (spriteset_Amfleet_Coach_purchase,"gfx/USA_Amtrak_Amfleet.png") { [4,   66,   87,   13,   5,   -6] }

spriteset (spriteset_Amfleet_Cafe,"gfx/USA_Amtrak_Amfleet.png") { tmpl_Amfleet(4,35) tmpl_Amfleet(92,35) }
spriteset (spriteset_Amfleet_Cafe_depot,"gfx/USA_Amtrak_Amfleet.png") { [36,  35,   32,   16,   -16,  -10] }
spriteset (spriteset_Amfleet_Cafe_purchase,"gfx/USA_Amtrak_Amfleet.png") { [92,   66,   87,   13,   5,   -6] }

switch(FEAT_TRAINS, SELF, sw_Amfleet_Coach_gui, getbits(extra_callback_info1, 0, 8) ) {
  0x00:  spriteset_Amfleet_Coach;
  spriteset_Amfleet_Coach_depot;
}

item (FEAT_TRAINS, item_Amfleet_Coach) {                                                                      
  property {
    name:                         string(STR_Amfleet_Coach_Name);                                                
    climates_available:           bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL); 
    introduction_date:            date(1975, 1, 6);      
    model_life:                   VEHICLE_NEVER_EXPIRES;                                             
    vehicle_life:                 20;                                                                                     
    refittable_cargo_classes:     bitmask(CC_PASSENGERS);                                                          
    non_refittable_cargo_classes: bitmask();
    loading_speed:                13; 
    cost_factor:                  25;                                                                           
    running_cost_factor:          1;                                                                             
    sprite_id:                    SPRITE_ID_NEW_TRAIN;        
    speed:                        201 km/h;                                                         
    misc_flags:                   bitmask();
    refit_cost:                   0;  
    track_type:                   RAIL;                                                                          
    ai_special_flag:              AI_FLAG_PASSENGER;
    power:                        0;                                                                                                                                     
    cargo_capacity:               84;                                                                            
    weight:                       49 ton;                                                                        
    ai_engine_rank:               0;                                                                                                                                                          
    tractive_effort_coefficient:  0.3;
    air_drag_coefficient:         0.06;    
    visual_effect_and_powered:    visual_effect_and_powered(VISUAL_EFFECT_DISABLE, 0, DISABLE_WAGON_POWER);
    extra_weight_per_wagon:       40 ton;
    bitmask_vehicle_info:         0;
    }
    graphics {
        purchase:                spriteset_Amfleet_Coach_purchase;               
        additional_text:         return string(STR_Amfleet_Coach_Desc);                                               
        length:                  8;
        default:                 sw_Amfleet_Coach_gui;                                                       
    }
}

switch(FEAT_TRAINS, SELF, sw_Amfleet_Cafe_gui, getbits(extra_callback_info1, 0, 8) ) {
  0x00:  spriteset_Amfleet_Cafe;
  spriteset_Amfleet_Cafe_depot;
}

item (FEAT_TRAINS, item_Amfleet_Cafe) {                                                                      
  property {
    name:                         string(STR_Amfleet_Cafe_Name);                                                
    climates_available:           bitmask(CLIMATE_TEMPERATE, CLIMATE_ARCTIC, CLIMATE_TROPICAL); 
    introduction_date:            date(1975, 1, 6);      
    model_life:                   VEHICLE_NEVER_EXPIRES;                                             
    vehicle_life:                 20;                                                                                     
    refittable_cargo_classes:     bitmask(CC_PASSENGERS);                                                          
    non_refittable_cargo_classes: bitmask();
    loading_speed:                13; 
    cost_factor:                  24;                                                                           
    running_cost_factor:          1;                                                                             
    sprite_id:                    SPRITE_ID_NEW_TRAIN;        
    speed:                        201 km/h;                                                         
    misc_flags:                   bitmask();
    refit_cost:                   0;  
    track_type:                   RAIL;                                                                          
    ai_special_flag:              AI_FLAG_PASSENGER;
    power:                        0;                                                                                                                                     
    cargo_capacity:               32;                                                                            
    weight:                       49 ton;                                                                        
    ai_engine_rank:               0;                                                                                                                                                          
    tractive_effort_coefficient:  0.3;
    air_drag_coefficient:         0.06;    
    visual_effect_and_powered:    visual_effect_and_powered(VISUAL_EFFECT_DISABLE, 0, DISABLE_WAGON_POWER);
    extra_weight_per_wagon:       40 ton;
    bitmask_vehicle_info:         0;
    }
    graphics {
        purchase:                spriteset_Amfleet_Cafe_purchase;               
        additional_text:         return string(STR_Amfleet_Cafe_Desc);                                                
        length:                  8;
        default:                 sw_Amfleet_Cafe_gui;                                                       
    }
}
Does your sprite file has 9 sprites (8 out of depot and 1 as purchase icon) ?
Tony Pixel
Route Supervisor
Route Supervisor
Posts: 459
Joined: 14 Oct 2017 11:06
Location: Ukraine

Re: Many NML questions

Post by Tony Pixel »

Yes
Image Image
Sprite artist and NewGRF developer, coding in NML. My projects:
NewGRFs: Not Enough Subways Set | North American Passenger Railroads | Elevated Subway Bridge | Tony Pixel's Subway Equipment Set (frozen)
Screenshots: New York City Subway Episodes
User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

Re: Many NML questions

Post by acs121 »

Did you place the sprites correctly in the file (8px between each view) ?
User avatar
Gwyd
Chief Executive
Chief Executive
Posts: 721
Joined: 17 Apr 2017 16:52
Location: Western Ile-de-France Region

Re: Many NML questions

Post by Gwyd »

A sprite being orphaned is not something to worry about: it's normal to get these.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 3 guests