Author Topic: what should l do if l want two speed? it doesn't work  (Read 4975 times)

0 Members and 1 Guest are viewing this topic.

Offline cypressx1

  • LV3 Member (Next: 100)
  • ***
  • Posts: 45
  • Rating: +0/-0
    • View Profile
what should l do if l want two speed? it doesn't work
« 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?

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: what should l do if l want two speed? it doesn't work
« Reply #1 on: July 09, 2011, 11:46:48 am »
are you trying to run both functions at once?

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: what should l do if l want two speed? it doesn't work
« Reply #2 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
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline cypressx1

  • LV3 Member (Next: 100)
  • ***
  • Posts: 45
  • Rating: +0/-0
    • View Profile
Re: what should l do if l want two speed? it doesn't work
« Reply #3 on: July 10, 2011, 06:17:26 am »
what should l write in event:init() ?

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: what should l do if l want two speed? it doesn't work
« Reply #4 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.
« Last Edit: July 10, 2011, 06:46:24 am by Levak »
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline cypressx1

  • LV3 Member (Next: 100)
  • ***
  • Posts: 45
  • Rating: +0/-0
    • View Profile
Re: what should l do if l want two speed? it doesn't work
« Reply #5 on: July 10, 2011, 06:56:32 am »
Got it !

Offline cypressx1

  • LV3 Member (Next: 100)
  • ***
  • Posts: 45
  • Rating: +0/-0
    • View Profile
Re: what should l do if l want two speed? it doesn't work
« Reply #6 on: July 10, 2011, 07:02:56 am »
 :love: do you have an E-mail address ?
« Last Edit: July 10, 2011, 07:03:24 am by cypressx1 »

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: what should l do if l want two speed? it doesn't work
« Reply #7 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.

Ashbad

  • Guest
Re: what should l do if l want two speed? it doesn't work
« Reply #8 on: July 10, 2011, 09:05:08 am »
And, don't double post within 6 hours.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: what should l do if l want two speed? it doesn't work
« Reply #9 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.