Running-Txt with txt_style

Questions about deployment and use of Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
FlyerDavidUK
Posts: 50
Joined: Mon May 04, 2020 9:04 am
Contact:

Running-Txt with txt_style

#1 Post by FlyerDavidUK »

I coded an altimeter display that changes colour when it deviates from the target altitude.

I created a running_txt object but can't seem to modify it using txt_style - it errors with a warning of nil value, so instead duplicated the object (with a different colour) and make only one visible at time.

This seems quite inefficient. Is it possible to modify running_txt objects (other than the text characters in the embedded function)?
Can you suggest a better way of doing this?

What I have does work, it just doesn't seem very elegant or efficient to me.
UK Private pilot and flight instructor with CPL/IR/FI/IRI approx 2000 hours offering remote flight instruction via Zoom
See my FlyerDavidUK.com website for trip reports around Europe/US, my training experience and services offered

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: Running-Txt with txt_style

#2 Post by SimPassion »

FlyerDavidUK wrote: Fri Nov 11, 2022 7:48 pm I coded an altimeter display that changes colour when it deviates from the target altitude.

I created a running_txt object but can't seem to modify it using txt_style - it errors with a warning of nil value, so instead duplicated the object (with a different colour) and make only one visible at time.

This seems quite inefficient. Is it possible to modify running_txt objects (other than the text characters in the embedded function)?
Can you suggest a better way of doing this?

What I have does work, it just doesn't seem very elegant or efficient to me.
Please post your logic.lua, otherwise it's still difficult to figure out what' the issue

FlyerDavidUK
Posts: 50
Joined: Mon May 04, 2020 9:04 am
Contact:

Re: Running-Txt with txt_style

#3 Post by FlyerDavidUK »

Deleted
Last edited by FlyerDavidUK on Fri Nov 25, 2022 8:14 pm, edited 1 time in total.
UK Private pilot and flight instructor with CPL/IR/FI/IRI approx 2000 hours offering remote flight instruction via Zoom
See my FlyerDavidUK.com website for trip reports around Europe/US, my training experience and services offered

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Running-Txt with txt_style

#4 Post by Keith Baxter »

FlyerDavidUK wrote: Fri Nov 25, 2022 10:59 am I have posted some code to clarify this question in the LUA and API scripting sub-forum
Hi,

Posting the same issue in multiple threads, discourages help from the community. Do not be impatient because you do not get an immediate answer. Peeps will help.It is not reasonable to expect members to navigate between threads. I suggest you delete delete thread https://siminnovations.com/forums/viewtopic.php?t=6667 and keep everything here.

Keith
Last edited by Keith Baxter on Fri Nov 25, 2022 11:43 am, edited 1 time in total.
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Running-Txt with txt_style

#5 Post by Keith Baxter »

Hi,

You need to sort out the syntax error at line two of the code you posted.

Code: Select all

   running_txt_move_carot(running_text_speed_1_white, (indicated_airspeed) * -1)
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

FlyerDavidUK
Posts: 50
Joined: Mon May 04, 2020 9:04 am
Contact:

Re: Running-Txt with txt_style

#6 Post by FlyerDavidUK »

@Keith Baxter My mistake. Not intending to confuse or complicate matters.

I have deleted the thread on the other forum so can focus on this one. I got the impression that I should have posted it there in the first place, which is why I did that.

I have copied the full sample demo code inline below rather than just a snippet above which would have caused a syntax error on its own.
Of course not everybody has the time or inclination to download/import the file I attached, so this code excerpt should run ok with theexception of not finding the two image files loaded at startup. These are included in the attachment.

Any comments or suggestions on alternative methods of implementing this colour change would be appreciated.
Test - Running Text Colour Demo.siff
(284.57 KiB) Downloaded 50 times

Code: Select all


--
-- Airspeed Indicator
--
--
local Vs0 = 44
local Vs1 = 50
local Vfe = 103
local Vno = 140
local Vne = 160

local MIN_SPEED_DISPLAYED = 20

gbl_power_on = 1

function init_speed_pointer()

    -- Text colours
    font_colour_cyan = "color: cyan;"
    font_colour_yellow = "color: yellow;"
    font_colour_magenta = "color: magenta;"
    font_colour_green = "color: #1dff0f;"
    font_colour_white = "color: white;"
    font_colour_grey = "color: #808080;"
	
    -- Fonts
    font_speed_clock_white = "size:55px; font:SourceSansPro-Bold.ttf; color:white; halign:right"
    font_speed_clock_yellow = "size:55px; font:SourceSansPro-Bold.ttf; color:yellow; halign:right"

    speedtape_pointer = img_add_fullscreen("speedtape_pointer.png")
    speedtape_pointer_red = img_add_fullscreen("speedtape_pointer_red.png")
    visible(speedtape_pointer,false)
    visible(speedtape_pointer_red,false)

    -- Current speed drum
    txt_speed_nil = txt_add("-  -  -",font_speed_clock_white,60,363,130,45)
    visible(txt_speed_nil,false)
    
    local function callback_running_text_speed_100(i)
        if (i == 0) then
            return " "
        else    
            return tostring((0 - i) % 10)
        end    
    end
          

    local function callback_running_text_speed(i)
        return tostring((0 - i) % 10)
    end

    running_text_speed_100_white = running_txt_add_ver(70, 320, 3, 55, 45, callback_running_text_speed_100, font_speed_clock_white)
    running_text_speed_100_yellow = running_txt_add_ver(70, 320, 3, 55, 45, callback_running_text_speed_100, font_speed_clock_yellow)
    running_text_speed_100 = group_add(running_text_speed_100_white,running_text_speed_100_yellow)
    viewport_rect(running_text_speed_100, 70 , 373 , 55, 45)

    running_text_speed_10_white = running_txt_add_ver(105, 320, 3 , 55 , 45, callback_running_text_speed, font_speed_clock_white)
    running_text_speed_10_yellow = running_txt_add_ver(105, 320, 3 , 55 , 45, callback_running_text_speed, font_speed_clock_yellow)
    running_text_speed_10 = group_add(running_text_speed_10_white,running_text_speed_10_yellow)
    viewport_rect(running_text_speed_10, 105 , 373, 55 , 45)

    running_text_speed_1_white = running_txt_add_ver(138, 275, 5 , 55, 45, callback_running_text_speed, font_speed_clock_white)
    running_text_speed_1_yellow = running_txt_add_ver(138, 275, 5 , 55, 45, callback_running_text_speed, font_speed_clock_yellow)
    running_text_speed_1 = group_add(running_text_speed_1_white,running_text_speed_1_yellow)
    viewport_rect(running_text_speed_1, 170, 345, 45, 103)

    grp_speeddrum_numbers_white = group_add(running_text_speed_1_white,running_text_speed_10_white,running_text_speed_100_white)
    grp_speeddrum_numbers_yellow = group_add(running_text_speed_1_yellow,running_text_speed_10_yellow,running_text_speed_100_yellow)
    visible(grp_speeddrum_numbers_white, false)
    visible(grp_speeddrum_numbers_yellow, false)
    
   
    grp_speed_pointer_all = group_add(speedtape_pointer,speedtape_pointer_red,txt_speed_nil)
    grp_speed_pointer_normal = group_add(speedtape_pointer,txt_speed_nil)
    visible(grp_speed_pointer_all,false)

    xpl_dataref_subscribe(
            "sim/cockpit2/gauges/indicators/airspeed_acceleration_kts_sec_pilot", "FLOAT",
            "sim/flightmodel/position/indicated_airspeed", "FLOAT", -- KIAS
            callback_speed_xpl)
           
    fsx_variable_subscribe(
            "AIRSPEED INDICATED", "Knots",
            callback_speed_fs)
           
    fs2020_variable_subscribe(
            "AIRSPEED INDICATED", "Knots",
            callback_speed_fs)

end

function callback_speed_fs(indicated_airspeed)
    callback_speed_xpl(0, indicated_airspeed)
end

function callback_speed_xpl(accel, indicated_airspeed)

                                        
    -- Speed text drums        
    running_txt_move_carot(running_text_speed_1_white, (indicated_airspeed) * -1)
    running_txt_move_carot(running_text_speed_1_yellow, (indicated_airspeed) * -1)
    if (indicated_airspeed % 10) >= 9 then
        running_txt_move_carot(running_text_speed_10_white, (indicated_airspeed %1 + math.floor( indicated_airspeed / 10 ) )* -1)
        running_txt_move_carot(running_text_speed_10_yellow, (indicated_airspeed %1 + math.floor( indicated_airspeed / 10 ) )* -1)
    else
        running_txt_move_carot(running_text_speed_10_white, math.floor( indicated_airspeed / 10 ) * -1)
        running_txt_move_carot(running_text_speed_10_yellow, math.floor( indicated_airspeed / 10 ) * -1)
    end
    if (indicated_airspeed % 100) >= 99 then
        running_txt_move_carot(running_text_speed_100_white, (indicated_airspeed %1 + math.floor( indicated_airspeed / 100 ) )* -1)
        running_txt_move_carot(running_text_speed_100_yellow, (indicated_airspeed %1 + math.floor( indicated_airspeed / 100 ) )* -1)
    else
        running_txt_move_carot(running_text_speed_100_white, math.floor( indicated_airspeed / 100 ) * -1)
        running_txt_move_carot(running_text_speed_100_yellow, math.floor( indicated_airspeed / 100 ) * -1)
    end  

    -- Show and move speedbug to correct position
    predicted_airspeed = indicated_airspeed + 6 * accel    

    visible(txt_speed_nil,gbl_power_on > 0 and indicated_airspeed < MIN_SPEED_DISPLAYED)
    visible(grp_speeddrum_numbers_white,(gbl_power_on > 0) and (indicated_airspeed >= Vne or predicted_airspeed < Vne) and (indicated_airspeed >= MIN_SPEED_DISPLAYED))
    visible(grp_speeddrum_numbers_yellow,(gbl_power_on > 0) and indicated_airspeed < Vne and predicted_airspeed >= Vne)
    visible(speedtape_pointer,gbl_power_on > 0 and indicated_airspeed < Vne)
    visible(speedtape_pointer_red,gbl_power_on > 0 and indicated_airspeed >= Vne)
 
    -- The following txt_style change of running_text_speed results in a compiler error
    --    txt_style(running_text_speed_10_white,fif(indicated_airspeed > 50),font_colour_magenta,font_colour_white)
 
end


function show_speed_tape(condition)
    if condition then
        visible(grp_speed_pointer_normal,true)
    else
        visible(grp_speed_pointer_all,false)
    end        
end


init_speed_pointer()
show_speed_tape(true)

UK Private pilot and flight instructor with CPL/IR/FI/IRI approx 2000 hours offering remote flight instruction via Zoom
See my FlyerDavidUK.com website for trip reports around Europe/US, my training experience and services offered

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Running-Txt with txt_style

#7 Post by Keith Baxter »

Hi,

No problem, now we are all on the thread and not criss crossing between the two.

When you call a text style it needs to be before the draw.

You can of course use canvas_draw()... or run different color tapes and make the relevant one visible or not.

I have not had the time to go through your code but will do so later tomorrow and revert

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

JackZ
Posts: 2262
Joined: Mon Feb 22, 2016 1:02 pm

Re: Running-Txt with txt_style

#8 Post by JackZ »

Apparently running_txt_add() doesn't allow any subsequent text-style change using text_style().
Once the text style has been created with running_txt_add_ver(x,y,nr_visible_items,item_width,item_height,value_callback,style)
it is fixed and cannot be changed afterwards.

So the solution of having two texts on top of each other and play with visibilty as you did, is the way to go until @Corjan adds the feature in a forthcoming version.

But I undersatnd your concern about potential performances issues, and I were you, i would simplify my code by only call the relevant

Code: Select all

running_txt_move_carot(running_text_speed_10_XXXX, math.floor( indicated_airspeed / 10 ) * -1)
, where XXXX is the color in use, instead of moving at each call both carrots. Move only the one that is actually displayed (the relavant one) to save a few msec.


My 10 cents!
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

Post Reply