Page 1 of 2

Many NML questions

Posted: 22 Mar 2018 20:05
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.

Re: Another guy which learns NML

Posted: 22 Mar 2018 21:10
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!

Re: Another guy which learns NML

Posted: 23 Mar 2018 14:43
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.

Re: Another guy which learns NML

Posted: 24 Mar 2018 06:52
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 808 times
I tried to change to UTF-8 all english.lang in both dir's (OYYD and NML), but anything goes.

Re: Another guy which learns NML

Posted: 24 Mar 2018 07:40
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?

Re: Another guy which learns NML

Posted: 24 Mar 2018 08:22
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.

Re: Another guy which learns NML

Posted: 30 Apr 2018 16:32
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?

Re: Another guy which learns NML

Posted: 30 Apr 2018 18:08
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:

Re: Another guy which learns NML

Posted: 01 May 2018 07:21
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

Re: Another guy which learns NML

Posted: 11 May 2018 06:20
by Tony Pixel
Ok, next question: how to use "getbits" function for the different sprites in GUI and game?

Re: Another guy which learns NML

Posted: 12 May 2018 23:02
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?

Re: Another guy which learns NML

Posted: 13 May 2018 06:19
by Tony Pixel
Thanks.

Re: Another guy which learns NML

Posted: 13 May 2018 06:37
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);                                                       
    }
}

Re: Another guy which learns NML

Posted: 15 May 2018 12:23
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;
  }
}

Re: Another guy which learns NML

Posted: 16 May 2018 12:33
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:

Re: Another guy which learns NML

Posted: 21 May 2018 16:39
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;                                                       
    }
}

Re: Another guy which learns NML

Posted: 21 May 2018 19:10
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) ?

Re: Many NML questions

Posted: 21 May 2018 19:11
by Tony Pixel
Yes

Re: Many NML questions

Posted: 21 May 2018 20:35
by acs121
Did you place the sprites correctly in the file (8px between each view) ?

Re: Many NML questions

Posted: 22 May 2018 14:27
by Gwyd
A sprite being orphaned is not something to worry about: it's normal to get these.