[nfo] Questions about text stack (now answered)

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

Moderator: Graphics Moderators

Post Reply
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

[nfo] Questions about text stack (now answered)

Post by andythenorth »

I am baffled by the text stack, and I would like for this to not be so...

Use case: text in industry window.

Current state: I can set text correctly with callback 3E, returning a single text ID to the cb. I can create a branching varaction 2 chain to return different text IDs according to various criteria (is the industry currently accepting input cargo 1 for example).

Desired state: the variation between the text is relatively small. It is wasteful of IDs to create near-identical texts with only a few words or a single line difference between them. It is harder to maintain, and will make translation more time consuming. I want to produce the appropriate text programatically, by combining sub-strings.

I have found and understood the purpose of text control code 80. I have successfully used it to crash the game :shock:

I have not understood (conceptually or in code) how to push something to the text stack. I'm slightly familiar with the %s pattern for string replacement, and I assume nfo wants something like:

Code: Select all

check variable
store a text ID (or other value) to the stack (using 0E?)
rinse and repeat until the stack has everything needed
return final text ID for text containing \80 control codes
cluestick?

cheers,

Andy
Last edited by andythenorth on 18 Oct 2009 20:12, edited 1 time in total.
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: [nfo] Questions about doing useful things with text

Post by Rubidium »

Be aware that some translations have a different ordering of words. So it might not be very wise to split strings too far. Especially if you intend it to be translated to non-Latin languages. Splitting on sentences is usually okay.
User avatar
AndersI
Tycoon
Tycoon
Posts: 1732
Joined: 19 Apr 2004 20:09
Location: Sweden
Contact:

Re: [nfo] Questions about doing useful things with text

Post by AndersI »

Just a +1 to Rubidium's comment. In general, don't build sentences by subtexts if you want it to translate. Don't think that one word in English is always replaced by one and the same word in another language - context changes can mean that completely different words should be used in two different sentences.

I've done real software translations, and one of the things that makes me swear at the originator is when a sentence is pasted together by code (there are more things to sear at...).

A translator needs context, context is (hopefully) available when there is a full sentence to translate, but more or less totally missing when all you have are free-standing words.
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: [nfo] Questions about doing useful things with text

Post by andythenorth »

Cookies for frosch, attached is some code that does the job.

In respect of translations, there shouldn't be a problem, the text I'm joining is separate sentences (separate paragraphs indeed). I'm just concatenating it because I have to have a single string for display. By the way, FIRS is already set up for translation somewhat :)

Code: Select all

// This code will make the industry window show whether the industry is accepting cargo Engineering Supplies
// LANG_ID1 and STR_INFO_ES_PRIMARY_BOOST etc is inserted by the pre-processor (makefile) used to build the FIRS nfo, ignore those and subsititute valid IDs instead 
// STR_INFO_ES_PRIMARY_BOOST ID would be D0 C0.  The text must include control character \80
// texts D0 D0 and D0 D1 are the "accepting" / "not accepting" texts that are inserted by text D0 C0, depending on cargo level  

-1 * 0 04 0A LANG_ID2 01 STR_INFO_ACCEPTING_ES D0 "\0D" 00 // empty line breaks to stop window size jumping around 
// ID would be D0 D0 ^^
-1 * 0 04 0A LANG_ID2 01 STR_INFO_NOT_ACCEPTING_ES D0 "\94Not Accepting Engineering Supplies\98\0D(Limit Reached)" 00
// ID would be D0 D1 ^^
-1 * 0 04 0A LANG_ID2 01 STR_INFO_ES_PRIMARY_BOOST D0 "\98Engineering supplies improve the chances of a production increase.\0D\0D\80" 00
// ID would be D0 C0


// cb 3A would also need to be enabled in the action 0 for the industry (will be prop 21 or 22, I forget which)


-1 * 0 02 0A BC //store sub-text ID to register, return text ID  
    85 // 
      1A 20 \wxD4D0 // create a value (constant 1A anded (20) with following bytes) 
      0E 1A 00 \wx100 // store in register
    \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both)
       STR_INFO_ES_PRIMARY_BOOST 80 00 00 00 00
     STR_INFO_ES_PRIMARY_BOOST 80 //default
-1 * 0 02 0A BB //store sub-text ID to register, return text ID  
    85 // 
      1A 20 \wxD4D1 // create a value (constant 1A anded (20) with following bytes) 
      0E 1A 00 \wx100 // store in register
    \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both)
       STR_INFO_ES_PRIMARY_BOOST 80 00 00 00 00
     STR_INFO_ES_PRIMARY_BOOST 80 //default
      
-1 * 0 02 0A BA //branch depending on cargo waiting (we want different text to show in industry window) 
  85 40 00 FF FF //check cargo waiting
  \b1 // range
    BB 00  \w200  FF FF    
  BC 00 // default	
	
	
-1 * 0 02 0A C0 //Handle callbacks
	85 0C //<type> <variable> word-access callback
	00 FF FF //no shift, no mask
	\b1 //number of ranges to check
    BA 00   3A 00   3A 00 //return text-ID D0xx if cb 3A (industry window)
	C1 00 //default
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 7 guests