Basically the sol.surface font text is equal to test for displaying words test1,2,3,4, etc. I am trying to overwrite the first 0-7 tests.
local test = {}
local testing
test[0] = "test1"
test[1] = "test2"
test[2] = "test3"
test[3] = "test4"
test[4] = "test5"
test[5] = "test6"
test[6] = "test7"
test[7] = "test8"
for i = 0,7 do
show_test[rep] = sol.text_surface.create({
text = test[i],
})
end
function sol.main:on_draw(screen)
--clear and overwrite
test = {}
if testing == true then
test[0] = "test_overwrite1"
test[1] = "test_overwrite2"
test[2] = "test_overwrite3"
test[3] = "test_overwrite4"
test[4] = "test_overwrite5"
test[5] = "test_overwrite6"
test[6] = "test_overwrite7"
test[7] = "test_overwrite8"
end
for i = 0,7 do
show_text[i]:draw(screen,x_test_pos,y_test_pos[i])
end
end
end
bump
Here you go. You need to have the following in the draw function. You need it to update...
---IN THE DRAW FUNCTION
for i = 0,7 do
show_test[rep] = sol.text_surface.create({
text = test[i],
})
end
Example:
local test = {}
local testing
test[0] = "test1"
test[1] = "test2"
test[2] = "test3"
test[3] = "test4"
test[4] = "test5"
test[5] = "test6"
test[6] = "test7"
test[7] = "test8"
function sol.main:on_draw(screen)
---IN THE DRAW FUNCTION
for i = 0,7 do
show_test[rep] = sol.text_surface.create({
text = test[i],
})
end
--clear and overwrite
test = {}
if testing == true then
test[0] = "test_overwrite1"
test[1] = "test_overwrite2"
test[2] = "test_overwrite3"
test[3] = "test_overwrite4"
test[4] = "test_overwrite5"
test[5] = "test_overwrite6"
test[6] = "test_overwrite7"
test[7] = "test_overwrite8"
end
for i = 0,7 do
show_text[i]:draw(screen,x_test_pos,y_test_pos[i])
end
end
end
Thank you Zefk! It works now.
I am not sure if I understand the question, but if you want to change the text of a text surface, use the function text_surface:set_text().
Also, instead of manually repeating some code here:
test[0] = "test1"
test[1] = "test2"
test[2] = "test3"
test[3] = "test4"
test[4] = "test5"
test[5] = "test6"
test[6] = "test7"
test[7] = "test8"
you can just concatenate strings:
for i = 1,8 do
test[i] = "test" .. i
end
(I also changed the loop to go from 1 to 8 (instead of 0 to 7) because this is the usual convention in Lua.)