Marcnamara2021 menu and coding help
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Re: Marcnamara2021 menu and coding help
hI!!!
Very, very thank you for the excellent support. Have a nice weekend!!
Best regards
Marcio
Very, very thank you for the excellent support. Have a nice weekend!!
Best regards
Marcio
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Re: Marcnamara2021 menu and coding help
Good Morning. Keith
Continuing the work of the MVP-50T, within my programming limitations, which I am gradually becoming familiar with, the menu is fully functional as far as Canvas is concerned. However, a task that I thought was simple, I am not achieving full success, which is the question of the visibilities (false or true) of the scripts of each canvas, which at first did not find a way to work. For example, the same Text that I insert on canvas 1 appears on all the others and vice versa, even if I give the conditions true or false on each one of them. Is there an explanation for my failure? If anyone in our community has had this issue and it has been resolved, I would appreciate it if you would direct me to the right forum topic.
Thank You
Marcio
Continuing the work of the MVP-50T, within my programming limitations, which I am gradually becoming familiar with, the menu is fully functional as far as Canvas is concerned. However, a task that I thought was simple, I am not achieving full success, which is the question of the visibilities (false or true) of the scripts of each canvas, which at first did not find a way to work. For example, the same Text that I insert on canvas 1 appears on all the others and vice versa, even if I give the conditions true or false on each one of them. Is there an explanation for my failure? If anyone in our community has had this issue and it has been resolved, I would appreciate it if you would direct me to the right forum topic.
Thank You
Marcio
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Marcnamara2021 menu and coding help
Hi,
Not sure. Can you post a short script that demonstrates the issue.
Keith
Not sure. Can you post a short script that demonstrates the issue.
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
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Re: Marcnamara2021 menu and coding help
I understand that I need to use a _txt before inserting a text in a specific Canvas(blue), without it being seen in another Canvas(yellow) that is in sequence in the menu. However, I am not able to use a function like _txt. Is there any function format that finction inside a canvas with the reuisito _txt?
txt_hoobs_hours2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:white; halign:right;", 108, 275, 90, 28)
-----
visible(txt_hoobs_hours2, false)
canvas_draw(system_canvas, function()
_rect(0,0,451,488)
_fill_img("system_screen_short.png",0,0,451,488)
function hoobs2(mts)
txt_set(txt_hoobs_hours2, string.format("%01.01f", mts) ) -----------------------------This way it works --- but it appears in all canvas
_txt(txt_hoobs_hours2, string.format("%01.01f", mts) ) -----------------------------This way not works
visible(txt_hoobs_hours2, true)
end
----------
xpl_dataref_subscribe("sim/cockpit2/clock_timer/hobbs_time_hours", "INT", hoobs2)
txt_hoobs_hours2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:white; halign:right;", 108, 275, 90, 28)
-----
visible(txt_hoobs_hours2, false)
canvas_draw(system_canvas, function()
_rect(0,0,451,488)
_fill_img("system_screen_short.png",0,0,451,488)
function hoobs2(mts)
txt_set(txt_hoobs_hours2, string.format("%01.01f", mts) ) -----------------------------This way it works --- but it appears in all canvas
_txt(txt_hoobs_hours2, string.format("%01.01f", mts) ) -----------------------------This way not works
visible(txt_hoobs_hours2, true)
end
----------
xpl_dataref_subscribe("sim/cockpit2/clock_timer/hobbs_time_hours", "INT", hoobs2)
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Marcnamara2021 menu and coding help
Hi,
Use _txt() within a canvas_draw()
Else your txt_add() ID <txt_hoobs_hours2> needs to be in a group which which you make visible or not.
Keith
Use _txt() within a canvas_draw()
Else your txt_add() ID <txt_hoobs_hours2> needs to be in a group which which you make visible or not.
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
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Re: Marcnamara2021 menu and coding help
Thank you very much!!
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Re: Marcnamara2021 menu and coding help
Please, just tell me what I did wrong.
---- ENTRADA DOS TEXTOS ---------------- DA SEÇÃO DE CANVAS DO MENU -----------------------------------------------------
txt_hoobs_hours2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:white; halign:right;", 108, 275, 90, 28)
pointer_f_total2 = img_add("pointer_f_total.png",227, 239, 15,15)
txt_fuel_total_white2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:white; halign:right;",348, 258, 70, 28)
pointer_aux_l2 = img_add("pointer_aux_l.png",227, 317, 15,15)
txt_aux_l_yellow2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:yellow; halign:right;", 350, 334, 70, 28)
txt_aux_l_white2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:white; halign:right;", 350, 334, 70, 28)
txt_aux_l_green2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:#7FFF00; halign:right;", 350, 334, 70, 28)
pointer_aux_r2 = img_add("pointer_aux_r.png",227, 389, 15,15)
txt_aux_r_yellow2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:yellow; halign:right;", 350, 406, 70, 28)
txt_aux_r_white2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:white; halign:right;", 350, 406, 70, 28)
txt_aux_r_green2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:#7FFF00; halign:right;", 350, 406, 70, 28)
txt_d_to_e2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:white; halign:right;", 100, 340, 90, 28)
--- IMAGENS DO TREM DE POUSO DA SEÇÃO CANVAS DO MENU SCROLL
img_pitch_indicator2 = img_add_fullscreen("pitch.png")
img_rudder_indicator2 = img_add_fullscreen("rudder.png")
img_trem_de_pouso2 = img_add_fullscreen("trem_de_pouso.png")
txt_canvasystem_group = group_add(txt_hoobs_hours2, pointer_f_total2,txt_fuel_total_white2, pointer_aux_l2,
txt_aux_l_yellow2, txt_aux_l_white2,txt_aux_l_green2,pointer_aux_r2,
txt_aux_r_yellow2,txt_aux_r_white2,txt_aux_r_green2,txt_d_to_e2)
---- ----------------------------this is one of the function I think I have write outside Canvas
function hoobs2(mts)
txt_set(txt_hoobs_hours2, string.format("%01.01f", mts) )
end
----------------------------- this I write inside canvas
canvas_draw(addfuel_canvas, function()
_rect(0,0,451,488)
_fill("red")
_txt(txt_hoobs_hours2, string.format("%01.01f", mts) )
visible(txt_canvasystem_group, true)
end)
------ return this error:
ERROR - error in draw callback: logic.lua bad argument #2 to 'format' (number expected, got nil)
Thank for the patiente.s
---- ENTRADA DOS TEXTOS ---------------- DA SEÇÃO DE CANVAS DO MENU -----------------------------------------------------
txt_hoobs_hours2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:white; halign:right;", 108, 275, 90, 28)
pointer_f_total2 = img_add("pointer_f_total.png",227, 239, 15,15)
txt_fuel_total_white2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:white; halign:right;",348, 258, 70, 28)
pointer_aux_l2 = img_add("pointer_aux_l.png",227, 317, 15,15)
txt_aux_l_yellow2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:yellow; halign:right;", 350, 334, 70, 28)
txt_aux_l_white2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:white; halign:right;", 350, 334, 70, 28)
txt_aux_l_green2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:#7FFF00; halign:right;", 350, 334, 70, 28)
pointer_aux_r2 = img_add("pointer_aux_r.png",227, 389, 15,15)
txt_aux_r_yellow2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:yellow; halign:right;", 350, 406, 70, 28)
txt_aux_r_white2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:white; halign:right;", 350, 406, 70, 28)
txt_aux_r_green2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:#7FFF00; halign:right;", 350, 406, 70, 28)
txt_d_to_e2 = txt_add("000", "font:Oita W01 Cond Bold.ttf;size:36px; color:white; halign:right;", 100, 340, 90, 28)
--- IMAGENS DO TREM DE POUSO DA SEÇÃO CANVAS DO MENU SCROLL
img_pitch_indicator2 = img_add_fullscreen("pitch.png")
img_rudder_indicator2 = img_add_fullscreen("rudder.png")
img_trem_de_pouso2 = img_add_fullscreen("trem_de_pouso.png")
txt_canvasystem_group = group_add(txt_hoobs_hours2, pointer_f_total2,txt_fuel_total_white2, pointer_aux_l2,
txt_aux_l_yellow2, txt_aux_l_white2,txt_aux_l_green2,pointer_aux_r2,
txt_aux_r_yellow2,txt_aux_r_white2,txt_aux_r_green2,txt_d_to_e2)
---- ----------------------------this is one of the function I think I have write outside Canvas
function hoobs2(mts)
txt_set(txt_hoobs_hours2, string.format("%01.01f", mts) )
end
----------------------------- this I write inside canvas
canvas_draw(addfuel_canvas, function()
_rect(0,0,451,488)
_fill("red")
_txt(txt_hoobs_hours2, string.format("%01.01f", mts) )
visible(txt_canvasystem_group, true)
end)
------ return this error:
ERROR - error in draw callback: logic.lua bad argument #2 to 'format' (number expected, got nil)
Thank for the patiente.s
Re: Marcnamara2021 menu and coding help
Please next time put your script between code brackets. The </> button.
Your text item in the canvas is wrong:
http://siminnovations.com/wiki/index.php?title=Txt
Your text item in the canvas is wrong:
http://siminnovations.com/wiki/index.php?title=Txt
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Marcnamara2021 menu and coding help
Hi,
Your issue is that you are using your text_add() as a var within a canvas_draw()
The text_add() will always be visible. If you want to use text_add() then you have to manage the text_add() visibility. Adding the text_add() node into a canvas_draw() node only invites the value. Not the visibility of the node.
It is best to use _txt() within canvas rather than the the text_add() var.
I wanted to demonstrate all those features.
@Ralph indicates correct.
Keith
Your issue is that you are using your text_add() as a var within a canvas_draw()
The text_add() will always be visible. If you want to use text_add() then you have to manage the text_add() visibility. Adding the text_add() node into a canvas_draw() node only invites the value. Not the visibility of the node.
It is best to use _txt() within canvas rather than the the text_add() var.
I wanted to demonstrate all those features.
@Ralph indicates correct.
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
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Re: Marcnamara2021 menu and coding help
Good Morning.
Could you please point me out where I'm wrong?
Thanks
marcio
Could you please point me out where I'm wrong?
Thanks
marcio
Code: Select all
----Creat font styles
robR_16witC="font:arimo_bold.ttf; size:16px; color: white; halign:left; valign:center;"
robR_24witC="font:arimo_bold.ttf; size:24px; color: white; halign:left; valign:center;"
robR_16yelC="font:arimo_bold.ttf; size:16px; color: yellow; halign:left; valign:center;"
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
--- green page text
txt_altimeter = txt_add("000", "font:arimo_bold.ttf;size:36px; color:white; halign:right;", 300, 200, 90, 30)
txt_de = txt_add("000", "font:arimo_bold.ttf;size:36px; color:white; halign:right;",300, 260, 90, 30)
greenpage_group = group_add(txt_de, txt_altimeter)
visible(greenpage_group, false)
--- red canvas function
function altimeter_XPL(alt)
txt_set(txt_altimeter, string.format("%01.00f", alt) )
end
function dme_XPL(dist)
txt_set(txt_de, string.format("%01.00f", dist) )
end
--- green page text
--- green page functions
------------------------------------------------------------------------------------------------------------
--- I am creating canvases that simulate your pages for demo purposes
red_canvas =canvas_add(0,0,600,600)
green_canvas =canvas_add(0,0,600,600)
yellow_canvas =canvas_add(0,0,600,600)
blue_canvas =canvas_add(0,0,600,600)
orange_canvas =canvas_add(0,0,600,600)
--Draw a background.
background = canvas_add(0, 0, 600, 600, function()
_rect(0,0,400,512)
_fill("blue")
end)
canvas_draw(red_canvas, function()
_rect(0,0,600,600)
_fill("red")
end)
canvas_draw(green_canvas, function()
_rect(0,0,600,600)
_fill("green")
txt_fuel_total = _txt("000", "font:;size:36px; color:white; halign:right;",200, 200)
txt_D_to_E = _txt("000", "font:;size:36px; color:white; halign:right;", 200, 240)
visible(greenpage_group, true)
end)
canvas_draw(yellow_canvas, function()
_rect(0,0,600,600)
_fill("yellow")
end)
canvas_draw(blue_canvas, function()
_rect(0,0,600,600)
_fill("blue")
end)
canvas_draw(orange_canvas, function()
_rect(0,0,600,600)
_fill("orange")
end)
visible(red_canvas, false)
visible(green_canvas, false)
visible(yellow_canvas, false)
visible(blue_canvas, false)
visible(orange_canvas, false)
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
--Create table for different Menues
menu1 ={"Red page","Green page","Yellow page","Blue page","Orange page"}
--- Here we create tables that are used for switching--- Here we create tables that are used for switching
visible_table0 = {false,false,false,false,false}
visible_table1 = {true,false,false,false,false}
visible_table2 = {false,true,false,false,false}
visible_table3 = {false,false,true,false,false}
visible_table4 = {false,false,false,true,false}
visible_table5 = {false,false,false,false,true}
vis_count_table = {visible_table1,visible_table2,visible_table3,visible_table4,visible_table5}
visible_master = visible_table0
print(visible_master)
---Test instrument to manually scroll pointer and highlight selected text
--Draw a menu.
menu = canvas_add(0, 0, 512, 512, function()
for i=1,#menu1 do
if i==1 then
_txt(menu1[i],robR_16yelC,50,10+(i*25))
else
_txt(menu1[i],robR_16witC,50,10+(i*25))
end
end
end)
--Draw a marker.
marker = canvas_add(0, 0, 20, 20, function()
_txt("►",robR_24witC,5,5,nil,nil)
end)
--position the marker
move(marker,20,25,nil,nil)
menu_group=group_add(menu,marker,background)
---------------------------------------------------------------------------------------------------
---Functions
---------------------------------------------------------------------------------------------------
point_pos=1
function dial_change(dir)
point_pos=var_cap(point_pos+dir,1,#menu1)
move(marker,20,0+(point_pos*25),nil,nil)
canvas_draw(menu, function()
for i=1,#menu1 do
if i==point_pos then
_txt(menu1[i],robR_16yelC,50,10+(i*25))
else
_txt(menu1[i],robR_16witC,50,10+(i*25))
end
end
end)
visible_master = vis_count_table[point_pos]
visibility()
end
but_count=0
function button_pressed()
but_count=but_count+1
if but_count > 1 then but_count =0 end
visible(menu_group,but_count==0)
print(but_count)
visibility()
end
function visibility()
visible(red_canvas, visible_master[1]and but_count==1)
visible(green_canvas, visible_master[2]and but_count==1)
visible(yellow_canvas, visible_master[3]and but_count==1)
visible(blue_canvas, visible_master[4]and but_count==1)
visible(orange_canvas, visible_master[5]and but_count==1)
end
-- Create Hardware
hw_dial_add("Menu Scroll", dial_change)
hw_button_add("Select button", button_pressed)
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/radio_altimeter_height_ft_pilot", "FLOAT", altimeter_XPL)
xpl_dataref_subscribe("sim/cockpit/radios/nav1_dme_dist_m", "FLOAT", dme_XPL)