Omnimaga

Calculator Community => TI Calculators => Lua => Topic started by: cypressx1 on July 09, 2011, 07:40:13 am

Title: what should l do if l want two speed? it doesn't work
Post by: cypressx1 on July 09, 2011, 07:40:13 am
event1=class()
function event1:paint(gc)
   gc:drawString("XX",x1,y1)
timer.start(0.1)
end
function event1:timer()
   x1=x1+1
   y1=y1+1
platform.window.invalidate()
end

event2=class()
function event2:paint(gc)
   gc:drawString("XXX",x2,y2)
timer.start(1)
end
function event2:timer()
   x2=x2+1
   y2=y2+1
platform.window.invalidate()
end

function on.paint(gc)
 event1():paint(gc)
 event2():paint(gc)
end
function on.timer()
 event1():timer()
 event2():timer()
end


------you know, it doesn't work. what should l do?
Title: Re: what should l do if l want two speed? it doesn't work
Post by: fb39ca4 on July 09, 2011, 11:46:48 am
are you trying to run both functions at once?
Title: Re: what should l do if l want two speed? it doesn't work
Post by: Levak on July 09, 2011, 12:56:30 pm
You forgot to define event1:init() and event2:init(), and then, you forgot to call them once.

This is a restriction of using class(), you may define a constructor, and call it to create the object
Title: Re: what should l do if l want two speed? it doesn't work
Post by: cypressx1 on July 10, 2011, 06:17:26 am
what should l write in event:init() ?
Title: Re: what should l do if l want two speed? it doesn't work
Post by: Levak on July 10, 2011, 06:45:24 am
what should l write in event:init() ?

Nothing, if you don't need so.

Actually, class() seperates the meta-tables and creates a new one to let you call event1 as a specific class. init() initializes the meta-table.
class() is not part of Lua, it is part of the TI Nspire framework, thus, it computerizes some routines to represent classes in Lua, even if it is not an object oriented language.
Title: Re: what should l do if l want two speed? it doesn't work
Post by: cypressx1 on July 10, 2011, 06:56:32 am
Got it !
Title: Re: what should l do if l want two speed? it doesn't work
Post by: cypressx1 on July 10, 2011, 07:02:56 am
 :love: do you have an E-mail address ?
Title: Re: what should l do if l want two speed? it doesn't work
Post by: Munchor on July 10, 2011, 09:03:41 am
:love: do you have an E-mail address ?

I'm not sure if this is the right place to ask for it, try PMing him.
Title: Re: what should l do if l want two speed? it doesn't work
Post by: Ashbad on July 10, 2011, 09:05:08 am
And, don't double post within 6 hours.
Title: Re: what should l do if l want two speed? it doesn't work
Post by: Munchor on July 10, 2011, 09:13:52 am
And, don't double post within 6 hours.

Indeed, I totally forgot that.

You can double post, but only if it's an update for a project or if it has been a long time since the last post.