Not sure this is a bug or if one has to code this way but it does not make sense to me.
I have a table with a a bunch of text to place in a canvas. The table looks like this.
Code: Select all
{
"character":
[
[
"Hellow World",
"style1b",
"50",
"50"
],
[
"Good By World",
"style1w",
"50",
"100"
]
]
{
Code: Select all
style1b= "font:arimo_regular.ttf; size:70; color: black; halign:center;valign:center;"
style1w= "font:arimo_regular.ttf; size:70; color: white; halign:center;valign:center;"
style2b= "font:arimo_regular.ttf; size:40; color: black; halign:center;valign:center;"
style2w= "font:arimo_regular.ttf; size:40; color: white; halign:center;valign:center;"
style3b= "font:arimo_regular.ttf; size:30; color: black; halign:center;valign:center;"
style3w= "font:arimo_regular.ttf; size:30; color: white; halign:center;valign:center;"
--- Lets place the text
for ti = 1, #char_data["character"] do
text_char = char_data["character"][ti][1]
text_style = char_data["character"][ti][2]
x3 = tonumber(char_data["character"][ti][3])
y3 = tonumber(char_data["character"][ti][4])
---******************************************************************---
_txt(text_char,text_style,x3,y3)
---******************************************************************---
end
To get the style to work I have to use a bunch of elseif's like this. Not elegant coding IMHO
Why is this?? Is it a bug??
Code: Select all
for ti = 1, #char_data["character"] do
text_char = char_data["character"][ti][1]
x3 = tonumber(char_data["character"][ti][3])
y3 = tonumber(char_data["character"][ti][4])
if char_data["character"][ti][2]=="style1w" then text_style = "font:arimo_regular.ttf; size:70; color: white; halign:center;valign:center;"
elseif char_data["character"][ti][2]=="style1b" then text_style = "font:arimo_regular.ttf; size:70; color: black; halign:center;valign:center;"
elseif char_data["character"][ti][2]=="style2w" then text_style = "font:arimo_regular.ttf; size:32; color: white; halign:center;valign:center;"
elseif char_data["character"][ti][2]=="style2b" then text_style = "font:arimo_regular.ttf; size:32; color: black; halign:center;valign:center;"
elseif char_data["character"][ti][2]=="style3w" then text_style = "font:arimo_regular.ttf; size:25; color: white; halign:center;valign:center;"
elseif char_data["character"][ti][2]=="style3b" then text_style = "font:arimo_regular.ttf; size:25; color: black; halign:center;valign:center;"
---******************************************************************---
_txt(text_char,text_style,x3,y3)
---******************************************************************---
end
This also works
Code: Select all
style1b= "font:arimo_regular.ttf; size:70; color: black; halign:center;valign:center;"
style1w= "font:arimo_regular.ttf; size:70; color: white; halign:center;valign:center;"
style2b= "font:arimo_regular.ttf; size:40; color: black; halign:center;valign:center;"
style2w= "font:arimo_regular.ttf; size:40; color: white; halign:center;valign:center;"
style3b= "font:arimo_regular.ttf; size:30; color: black; halign:center;valign:center;"
style3w= "font:arimo_regular.ttf; size:30; color: white; halign:center;valign:center;"
--- Lets place the text
for ti = 1, #char_data["character"] do
text_char = char_data["character"][ti][1]
x3 = tonumber(char_data["character"][ti][3])
y3 = tonumber(char_data["character"][ti][4])
if char_data["character"][ti][2]=="style1w" then text_style = style1w
elseif char_data["character"][ti][2]=="style1b" then text_style = style1b
elseif char_data["character"][ti][2]=="style2w" then text_style = style2w
elseif char_data["character"][ti][2]=="style2b" then text_style = style2b
elseif char_data["character"][ti][2]=="style3w" then text_style = style3w
elseif char_data["character"][ti][2]=="style3b" then text_style = style3b
---******************************************************************---
_txt(text_char,text_style,x3,y3)
---******************************************************************---
end
Keith