Need help with switching train graphics in NML

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

Moderator: Graphics Moderators

Post Reply
THESlickSalmon
Engineer
Engineer
Posts: 3
Joined: 03 Sep 2023 19:11

Need help with switching train graphics in NML

Post by THESlickSalmon »

I'm making a grf using NML where I need to be able to be able to switch between the spritesets of a locomotive based on 2 factors:
-1: Vehicle Refit, I have 3 different liveries which can be chosen to be used on the locomotive.
-2: If the Locomotive has been flipped (facing forward or backward within the consist), Each livery has 2 spritesets, one for if the locomotive is not flipped, and one for if it is flipped.

what I currently have is this

Code: Select all

//cargo subtype text for GP38-2 refits
switch(FEAT_TRAINS, SELF, switch_GP38_2_cargo_subtype_text, cargo_subtype) {
	0: return string(STR_CP_BASIC_RED);
	1: return string(STR_CP_RED_WITH_BEAVER);
	2: return string(STR_CP_RAIL_SYSTEMS_FLAG);
	return CB_RESULT_NO_TEXT;
}

//choose livery
switch(FEAT_TRAINS, SELF, switch_GP38_2_livery, cargo_subtype) {
	0: switch_GP38_2_CP_Red_facing;
	1: switch_GP38_2_CP_Beaver_facing;
	2: switch_GP38_2_CP_Flag_facing;
}

//CP Red GP38-2
switch(FEAT_TRAINS, SELF, switch_GP38_2_CP_Red_facing, vehicle_is_flipped) {
	0: spriteset_GP38_2_CP_Red_engine_forward;
	spriteset_GP38_2_CP_Red_engine_reverse;
}

//CP Golden Beaver GP38-2
switch(FEAT_TRAINS, SELF, switch_GP38_2_CP_Beaver_facing, vehicle_is_flipped) {
	0: spriteset_GP38_2_CP_Beaver_engine_forward;
	spriteset_GP38_2_CP_Beaver_engine_reverse;
}

//CP Dual Flag GP38-2
switch(FEAT_TRAINS, SELF, switch_GP38_2_CP_Flag_facing, vehicle_is_flipped) {
	0: spriteset_GP38_2_CP_Flag_engine_forward;
	spriteset_GP38_2_CP_Flag_engine_reverse;
}
The cargo_subtype switch block is used to identify which of the 3 liveries was chosen, for each livery there is a switch block which checks if the loco is flipped and switch between the forward facing spriteset, and the backwards facing one.

My problem is that I'm getting an error that the "vehicle_is_flipped" switch blocks seem to not exist, the compiler will get to the choose livery switch, but will then give me a "Unrecognized identifier 'switch_GP38_2_CP_Red_facing' encountered" error for option 0 of the choose livery switch block

I can't seem to find anything in the documentation about this, nor can I find any articles in the forum that cover this issue. Any help will be appreciated.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5631
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Need help with switching train graphics in NML

Post by PikkaBird »

Hello and welcome. :)

Switches chain from the bottom up, so you just need to reverse the order of the code blocks.
THESlickSalmon
Engineer
Engineer
Posts: 3
Joined: 03 Sep 2023 19:11

Re: Need help with switching train graphics in NML

Post by THESlickSalmon »

thanks, I'll come back after I try it
THESlickSalmon
Engineer
Engineer
Posts: 3
Joined: 03 Sep 2023 19:11

Re: Need help with switching train graphics in NML

Post by THESlickSalmon »

it worked, thank you so much :bow:
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 11 guests