Yeah i don't mind.MysticPing2 wrote:Also, since im only using this for a simple tax calculator for a forum, is it OK if i use and alter your code (and distribute it, ofcorse i wont earn money on it )
I learn alot from reading it
-- I keep pressing save instead of submit
Hello, trying to print a text i input
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Hello, trying to print a text i input
-
- Prole
- Posts: 33
- Joined: Tue Dec 10, 2013 7:08 pm
Re: Hello, trying to print a text i input
console works now, not shure how, your fingers must be magic
-
- Prole
- Posts: 33
- Joined: Tue Dec 10, 2013 7:08 pm
Re: Hello, trying to print a text i input
I tried adding another table, text_box2 and doing the same variables, and then c+v'ing the other functions and replacing the tex_box with textbox_2, its not reallt working
Re: Hello, trying to print a text i input
Define "not working". Also if could post the code that would help.MysticPing2 wrote:I tried adding another table, text_box2 and doing the same variables, and then c+v'ing the other functions and replacing the tex_box with textbox_2, its not reallt working
-
- Prole
- Posts: 33
- Joined: Tue Dec 10, 2013 7:08 pm
Re: Hello, trying to print a text i input
Basicly it behaves like i didnt edit it at all, exept when i press backspace all text disssapear
I changed that
And for ever other function i created a copy and replaced the names, example:
Code: Select all
function love.load()
text_box = { --Table that holds all the textbox properties
x = 12,
y = 12,
width = 256,
height = 24,
text = "",
selected = false
}
text_box2 = {
x = 12,
y = 48,
width = 256,
height = 24,
text = "",
selected = false
}
end
And for ever other function i created a copy and replaced the names, example:
Code: Select all
function love.draw()
--Drawing the textbox
if text_box2.selected then --Settting the color to bright red if the textbox is selected, and dark red if not.
love.graphics.setColor(255, 0, 0)
else
love.graphics.setColor(100, 0, 0)
end
love.graphics.rectangle("line", text_box2.x, text_box2.y, text_box2.width, text_box2.height)
love.graphics.setColor(255, 255, 255)
love.graphics.print(text_box2.text, text_box2.x + 5, text_box2.y + 5)
end
Re: Hello, trying to print a text i input
There should only be one of each of the callback functions (love.load, love.draw, love.update, love.mousepressed etc.).
So if you have multiple boxes, You draw them all in one love.draw.
like this:
Like i already mentioned, This isn't really a proper implementation. Ideally you would store all the textboxes in a table, then to draw them you would loop through that table with a for loop and draw it that way, Would make the code significantly cleaner and shorter.
So if you have multiple boxes, You draw them all in one love.draw.
like this:
Code: Select all
function love.draw()
--Drawing the textbox
if text_box1.selected then --Settting the color to bright red if the textbox is selected, and dark red if not.
love.graphics.setColor(255, 0, 0)
else
love.graphics.setColor(100, 0, 0)
end
love.graphics.rectangle("line", text_box1.x, text_box1.y, text_box1.width, text_box1.height)
love.graphics.setColor(255, 255, 255)
love.graphics.print(text_box1.text, text_box1.x + 5, text_box1.y + 5)
if text_box2.selected then
love.graphics.setColor(255, 0, 0)
else
love.graphics.setColor(100, 0, 0)
end
love.graphics.rectangle("line", text_box2.x, text_box2.y, text_box2.width, text_box2.height)
love.graphics.setColor(255, 255, 255)
love.graphics.print(text_box2.text, text_box2.x + 5, text_box2.y + 5)
end
-
- Prole
- Posts: 33
- Joined: Tue Dec 10, 2013 7:08 pm
Re: Hello, trying to print a text i input
thanks, i have to go now and while i might be online at school, i havnt figured out how to run stuff on my mac yet, but well thanks.
As for looping trough would i do all the tables in 1 table and do it like this? Whereas when i wanted to do something i would do
for i=1,#text_boxes do
text_boxes -- would be what i used?
well as i said g2g now, thank you, you are awesome
forgot to mention it would be like
if i > #text_boxes then
i = 1
-- then i would have some kind of wait inbetween updates
As for looping trough would i do all the tables in 1 table and do it like this? Whereas when i wanted to do something i would do
for i=1,#text_boxes do
text_boxes -- would be what i used?
well as i said g2g now, thank you, you are awesome
forgot to mention it would be like
if i > #text_boxes then
i = 1
-- then i would have some kind of wait inbetween updates
Re: Hello, trying to print a text i input
MysticPing2 wrote:thanks, i have to go now and while i might be online at school, i havnt figured out how to run stuff on my mac yet, but well thanks.
As for looping trough would i do all the tables in 1 table and do it like this? Whereas when i wanted to do something i would do
for i=1,#text_boxes do
text_boxes -- would be what i used?
well as i said g2g now, thank you, you are awesome
That would work, but you could use an ipairs loop instead.
-
- Prole
- Posts: 33
- Joined: Tue Dec 10, 2013 7:08 pm
Re: Hello, trying to print a text i input
I dont really understand ipairs, though
Re: Hello, trying to print a text i input
It's pretty simple, Say you have a table like this:MysticPing2 wrote:I dont really understand ipairs, though
Code: Select all
things = {"thing", "another thing", and one more thing"}
Code: Select all
for i,v in ipairs(things) do
--do things here
end
Code: Select all
love.graphics.print(v, 12, 12)
Code: Select all
love.graphics.print(things[i], 12, 12)
ipairs is design to iterate through tables, So your code will be a bit cleaner, and quicker to type with ipairs as opposed to a numeric loop.
Who is online
Users browsing this forum: Google [Bot] and 8 guests