Scrolling text problems.

Hola! I’m trying to figure out a couple of thing. I’m creating an app that has lots of facts. I will input all of these facts using util.wrappedText.

Question 1: How do I separate the facts. For example; On one line have the fact “Butterflies are insects”. Then in a specified spacing below add another fact such as “Don’t eat the red butterflies”. And be able to continue the format.

Question 2: How do you center the type, It’s always flush left.

Question 3: Is this the right way to go about doing something like this?

Thanks in advance!!

[import]uid: 10062 topic_id: 3748 reply_id: 303748[/import]

Okay I have decided I dont like the scroll. I’m on to just touching an object and changing facts. Which bring me to another question.

How to I call another lua script? Again, I’m trying to write an app that has lots of facts. Basically I have a screen with buttons. When a button is touched a fact will appear. I would like the fact to come on in a random order and discard the the ones viewed until reset. My thought was to have separate lua scripts that will have the various facts then call them in the main lua file.

Any thoughts or suggestions will be greatly appreciated!

Thanks! [import]uid: 10062 topic_id: 3748 reply_id: 11431[/import]

Off the top of my head if I wanted a bunch of facts to present to the user I’d create a table (array) of facts, shuffle them, and then just start “dealing them” from the first element of the array (table). Since you already shuffled you can just show the first value, second value, third value, etc., whenever they tap.

To reset, just shuffle the table again and then reset the counter to 1 and start showing the facts again.

If you Google “shuffle lua table” you’ll find several examples you can probably make use of.

Jay
[import]uid: 9440 topic_id: 3748 reply_id: 11473[/import]

Here’s a quick test I put together using found and created code – it shuffles the table and prints it out so you can see the random order.

math.randomseed( os.time() )  
  
function shuffle(t)  
 local n = #t  
 while n \> 2 do  
 local k = math.random(n)  
 t[n], t[k] = t[k], t[n]  
 n = n - 1  
 end  
 return t  
end  
  
local myfacts = {"This is one.", "This is two.", "That is three.", "Here is four."}  
  
shuffle(myfacts)  
  
for k, v in ipairs (myfacts) do  
 print (v)  
end  

I hope that helps.

Jay
[import]uid: 9440 topic_id: 3748 reply_id: 11475[/import]

Awesome! Thanks Jay!! I’m going to try it out today. I’m really new with lua and I know this is easy for some but not me. I really appreciate people like you helping others!! Thanks again! I’ll let you know how it works.

Stan- [import]uid: 10062 topic_id: 3748 reply_id: 11520[/import]

Hey, I hope it gets you on the right track, anyway. I’m new to Lua myself, but not to programming – I’ve been doing that basically full time since the mid-late 80s.

So I can usually come up with a way to do something, but being new to Lua (and Corona) it may not be the optimum way to do it.

However, that fits in with my general philosophy – make it work first, and then worry about making it better/faster later. :slight_smile:

Jay
[import]uid: 9440 topic_id: 3748 reply_id: 11584[/import]