Is Lua mainly for animation? I know practically nothing about coding, but I want to learn enough to code a simple app I want. The app isn’t gaming or animated. It is a news app. Basically, it’s a news app. I want to basically create a main screen that has two columns, on the left side there will be the names of two newspapers. When you select one, on the right column a list of all the names of that newspapers columnists will appear, and you simply click on their name and it takes you to their page. Can I create this on Lua?
Hello @kaplant4 welcome to the forums. Lua in itself is mainly used for UI in the gaming industry, this isn’t to say it’s the best for UI or restricted to that. Lua can be used for almost anything, what hinders its use is speed mainly. Because its not a low-down language like C or the likes, it will be slow for certain operations such as for loops which slow down a lot when they get past a certain point.
The problems mainly arise when trying to create a big project with Lua (especially Codea) where things just seem to no longer be deterministic, but there is usually a reason for it. The idea you put forward above can definitely be done with Codea with ease, and you’ll mainly be using tables which is Lua’s ‘winning card’ if you like. Very optimised and should make for good use in a newspaper/column app.
@kaplant4 - actually, I think another app may be more suitable, because although you can get Lua to do this, it is mainly an animation/graphic app, and isn’t optimised for drawing text or drawing static screens. Maybe pythonista instead.
@Ignatz, @kaplant4, I think Codea is perfectly suitable for this. As @Luatee said, Lua is great with tables which is mainly what this app would use from my pov, and it has the ability to load pages. plus, with a bit of work you can make a very nice looking table/card layout ui
I think you can, you have to use a state machine, write some engine to make a toolbar and the left panel and a page viewer at the right. Codea is not mainly for this kind of app, but is not limited to this.
@kaplant4 Here’s something I wrote long ago. I modified it so it looks like what I think you’re after. When you press a button to go to another URL, press “Done” in the upper left corner to return back to the program. Just change the names and URL for each columnist.
displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT_ANY)
function setup()
func=menu -- start screen
buttonTab={} -- buttons table
-- button(x,y,width,height,button name,button screen,button function)
-- buttons that show on the menu screen
table.insert(buttonTab,button(350,800,200,100,"New York Times",menu,screen1))
table.insert(buttonTab,button(350,500,200,100,"USA Today",menu,screen2))
table.insert(buttonTab,button(700,50,100,50,"EXIT",menu,close))
-- Screen 1 buttons
table.insert(buttonTab,button(350,900,200,75,"Columnist1",screen1,url1))
table.insert(buttonTab,button(350,800,200,75,"Columnist2",screen1,url2))
table.insert(buttonTab,button(350,100,150,50,"Menu",screen1,menu))
-- Screen 2 buttons
table.insert(buttonTab,button(350,900,200,75,"Columnist1",screen2,url3))
table.insert(buttonTab,button(350,800,200,75,"Columnist2",screen2,url4))
table.insert(buttonTab,button(350,100,150,50,"Menu",screen2,menu))
end
function draw()
background(40, 40, 50)
fill(255)
func() -- call the function set by the button
end
function touched(t) -- check if a button was pressed
if t.state==BEGAN then
for a,b in ipairs(buttonTab) do
if b:touched(t) then
break
end
end
end
end
function menu()
background(58, 97, 136, 255)
fontSize(30)
text("Menu Screen",350,1000)
drawButtonTab()
end
function screen1()
background(101, 43, 43, 255)
fontSize(30)
text("New Your Times",350,1000)
drawButtonTab()
end
function screen2()
background(110, 165, 74, 255)
fontSize(30)
text("Wall Street Journal",350,1000)
drawButtonTab()
end
function url1()
openURL('http://www.google.com',true)
func=screen1 -- return to screen1
end
function url2()
openURL('http://twolivesleft.com',true)
func=screen1 -- return to screen1
end
function url3()
openURL('http://www.mapquest.com',true)
func=screen2 -- return to screen2
end
function url4()
openURL('http://www.amazon.com',true)
func=screen2 -- return to screen2
end
function drawButtonTab() -- draw selected buttons from button table
fontSize(20)
for a,b in ipairs(buttonTab) do
b:draw()
end
end
button=class()
function button:init(x,y,w,h,name,screen,func)
self.x=x -- x position
self.y=y -- y position
self.w=w -- width
self.h=h -- height
self.name=name -- name to put on the button
self.screen=screen -- screen to draw the button on
self.func=func -- function to call when the button is pressed
end
function button:draw()
if func==self.screen then -- draw the button
fill(31, 178, 212, 255)
ellipse(self.x,self.y,self.w,self.h)
fill(255, 0, 0, 255)
text(self.name,self.x,self.y)
end
end
function button:touched(t)
if func==self.screen then -- only check current screen button
if t.x>self.x-self.w/2 and t.x<self.x+self.w/2 and
t.y>self.y-self.h/2 and t.y<self.y+self.h/2 then
func=self.func
return true
end
return false
end
end
Then there’s me… The one who hates scripting languages (other than Python) and prefers native UIs. I think that using a UITableView and a UISplitViewController with Cocoa Touch would be best. You will also have much more customization visually, an app that is super small in size, and it’d be faster. However, you would not be able to code that on your iPad.
Edit: I forgot that Pythonista supports UI elements now. So I do suggest using Pythonista if you really want to write the app on your iPad.
To be pedantic, lua is good for writing programs… it’s a programming language. You probably have a spectrum of lua → python → objective-C where lua is lightweight and light on features, and objective-C is heavyweight and heavy on features and python is in the middle (nearer lua than C).
Any of these languages can do almost anything and it’s really down to personal preference.
But the question above is more correctly “Is Codea mainly for” as Codea has an API and standard program structure which is broadly a game loop and lots of custom graphics type loveliness. So while you can write apps in Codea, it is probably going to be more productive writing apps with a tool that gives you APIs for the native controls, so you can just stick in a button, you don’t have to build a button with graphics and touch handling yourself.
@kaplant4 —Adding on to @spacemonkey, Codea is better at games and simulations, and while an app like that can be made, it’s better to use Cocoa Touch and Objective-C (and Swift if you have the Xcode 6 beta - not really sure what its for though).
@Jmv38 I know about your library and people have things for all types of stuff on the forum, it was just an easy example to bring to mind. Something like objective-C or pythonista has it native, in Codea you have to do it yourself or find someone elses code to do it.