Can't refer to switches

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

Moderator: Graphics Moderators

Post Reply
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Can't refer to switches

Post by Erato »

I want to set some values of a wagon with switches, like so:

Code: Select all

//Sets weight of the passenger carriage based on the engine.
switch(FEAT_TRAINS, PARENT, PASS_WEIGHT,  vehicle_type_id) {
   ITEM_LINIMO: return 35;
   ITEM_SMT: return 70;
   default: return 0;
}
//Checks for native grfid
switch(FEAT_TRAINS, PARENT, PASS_WEIGHT_CHECK, grfid) {
   str2number("EN\01\01"): return PASS_WEIGHT;
   default: return 0;
}
//Passenger Car
item(FEAT_TRAINS, ITEM_PASS) {
	property {
		...
		weight: PASS_WEIGHT_CHECK;
		....
	}
}
But this doesn't seem to work, because I get this error message:

Code: Select all

 Binary operator requires both operands to be integers.
Does someone happen to know what I'm doing wrong?
No pics no clicks. Seriously.
ImageImageImageImageImageImage
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Can't refer to switches

Post by Alberth »

That code has no binary operator, as far as I can see. What line number does the error refer to?
Being a retired OpenTTD developer does not mean I know what I am doing.
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: Can't refer to switches

Post by Erato »

Alberth wrote:That code has no binary operator, as far as I can see. What line number does the error refer to?

Code: Select all

      weight: PASS_WEIGHT_CHECK;
that one
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Can't refer to switches

Post by planetmaker »

Erato wrote:
Alberth wrote:That code has no binary operator, as far as I can see. What line number does the error refer to?

Code: Select all

      weight: PASS_WEIGHT_CHECK;
that one
A property is always a constant. If you want varying weight, you have to additionally define the weight callback in the graphics block. Granted, the error message is not exactly helpful - I made a note about that :)

Code: Select all

//Sets weight of the passenger carriage based on the engine.
switch(FEAT_TRAINS, PARENT, pass_weight_switch,  vehicle_type_id) {
   0: return 35;
   1: return 70;
   default: return 0;
}
//Checks for native grfid
switch(FEAT_TRAINS, PARENT, pass_weight_checks, grfid) {
   0xFFEEBBCC: pass_weight_switch;
   default: return 0;
}
//Passenger Car
item(FEAT_TRAINS, item_passenger_wagon, 0) {
   graphics {
      weight: pass_weight_checks;
   }
}
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: Can't refer to switches

Post by Erato »

planetmaker wrote:
Erato wrote:
Alberth wrote:That code has no binary operator, as far as I can see. What line number does the error refer to?

Code: Select all

      weight: PASS_WEIGHT_CHECK;
that one
A property is always a constant. If you want varying weight, you have to additionally define the weight callback in the graphics block. Granted, the error message is not exactly helpful - I made a note about that :)

Code: Select all

//Sets weight of the passenger carriage based on the engine.
switch(FEAT_TRAINS, PARENT, pass_weight_switch,  vehicle_type_id) {
   0: return 35;
   1: return 70;
   default: return 0;
}
//Checks for native grfid
switch(FEAT_TRAINS, PARENT, pass_weight_checks, grfid) {
   0xFFEEBBCC: pass_weight_switch;
   default: return 0;
}
//Passenger Car
item(FEAT_TRAINS, item_passenger_wagon, 0) {
   graphics {
      weight: pass_weight_checks;
   }
}
It isn't working for passenger capacities.
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Can't refer to switches

Post by planetmaker »

Erato wrote:
planetmaker wrote:
Erato wrote:

Code: Select all

      weight: PASS_WEIGHT_CHECK;
that one
A property is always a constant. If you want varying weight, you have to additionally define the weight callback in the graphics block. Granted, the error message is not exactly helpful - I made a note about that :)

Code: Select all

//Sets weight of the passenger carriage based on the engine.
switch(FEAT_TRAINS, PARENT, pass_weight_switch,  vehicle_type_id) {
   0: return 35;
   1: return 70;
   default: return 0;
}
//Checks for native grfid
switch(FEAT_TRAINS, PARENT, pass_weight_checks, grfid) {
   0xFFEEBBCC: pass_weight_switch;
   default: return 0;
}
//Passenger Car
item(FEAT_TRAINS, item_passenger_wagon, 0) {
   graphics {
      weight: pass_weight_checks;
   }
}
It isn't working for passenger capacities.
Obviously the weight doesn't change the capacity. That's a separate callback, cargo_capacity.

You would help yourself more, if you would be quite a bit more elaborate http://stackoverflow.com/help/how-to-ask
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: Can't refer to switches

Post by Erato »

planetmaker wrote:<snip>

Obviously the weight doesn't change the capacity. That's a separate callback, cargo_capacity.

You would help yourself more, if you would be quite a bit more elaborate http://stackoverflow.com/help/how-to-ask
Ah, ofc.
I used the same trick as I did for the weight, with the switch, but for some reason, it didn't work, the cargo capacity of the wagon remains 0.

Code: Select all

...
//Sets passenger cap of the passenger carriage based on the engine.
switch(FEAT_TRAINS, PARENT, PASS_CAP,  vehicle_type_id) {
	ITEM_LINIMO: return 80;
	ITEM_TRR: return 190;
	ITEM_IAM: return 100;
	default: return 0;
}
...
//Checks for native grfid
switch(FEAT_TRAINS, PARENT, PASS_CAP_CHECK, grfid) {
   str2number("EN\01\01"): return PASS_CAP;
   default: return 0;
}
...
//Passenger Car
item(FEAT_TRAINS, ITEM_PASS) {
	property {
		...
		refittable_cargo_classes: bitmask(CC_PASSENGERS);
		cargo_allow_refit: [PASS, TOUR];
		...
	}
	graphics {
		default: PASS_GFX_CHECK;
		weight: PASS_WEIGHT_CHECK;
		cargo_capacity: PASS_CAP_CHECK;
		...
	}
}
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Can't refer to switches

Post by planetmaker »

With that code you force the capacity to be 0 except when attached to those engines. Thus in the purchase list it will always be listed as 0. And thus might even not become available, dunno. But I'm guessing again as I don't know what you mean with "doesn't work". EDIT: What is the actual result? Always capacity 0 even when attached to those engines? Only in purchase list? Wagons not available? </EDIT> Nor do I see compilable code / source to verify / check myself (yes, I'm lazy, too).
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: Can't refer to switches

Post by Erato »

planetmaker wrote:With that code you force the capacity to be 0 except when attached to those engines. Thus in the purchase list it will always be listed as 0. And thus might even not become available, dunno. But I'm guessing again as I don't know what you mean with "doesn't work". EDIT: What is the actual result? Always capacity 0 even when attached to those engines? Only in purchase list? Wagons not available? </EDIT> Nor do I see compilable code / source to verify / check myself (yes, I'm lazy, too).
With "doesn't work" I meant that the capacity would always be N/A. I tried using a default of 1 too, but that didn't work either.
No pics no clicks. Seriously.
ImageImageImageImageImageImage
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: Can't refer to switches

Post by Transportman »

Can you check what happens when you set the various defaults to something else than 0? Then you can pinpoint which switch is not working properly and help you in solving the problem (or help us in helping you). My guess would be grfid check where you do a str2number, which I think is wrong, but I'm not sure about that.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Can't refer to switches

Post by planetmaker »

Foremost, you should set the property value to something else than 0. "It" is ambiguous when talking of two things, properties *and* callbacks.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 8 guests