Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Jim Bauwens

Pages: 1 ... 88 89 [90] 91 92 ... 125
1336
News / Re: OmnomIRC moved to new server
« on: August 18, 2011, 12:13:55 pm »
You could always access it through an irc client, but on EFnet ;)

1337
Lua / Re: Lua Q&A
« on: August 18, 2011, 11:37:08 am »
Yes, I forgot to mention that. Thanks Lionel :)

1338
Lua / Re: Lua Q&A
« on: August 18, 2011, 11:29:38 am »
Hm, should work. I didn't have any problems. I hope it isn't because its trial x)
Maybe your cable is a bit damaged?

1339
Lua / Re: Lua Q&A
« on: August 18, 2011, 11:08:53 am »
That above string just error's when I enter it into my calculator. Maybe because its running in a coroutine.

1340
General Calculator Help / Re: The speed of Nspire CX CAS
« on: August 18, 2011, 10:30:29 am »
Well, I guess it means that something is unoptimized, as the cpu frequency is higher. Or maybe it has more work with the colors.

1341
Lua / Re: Lua problems and bugs
« on: August 18, 2011, 06:00:34 am »
Oh, so it will become even become better \o/
Thanks for enlightening us :)

1342
Lua / Re: Lua Classes
« on: August 18, 2011, 05:53:08 am »
Adriweb was planning to do it when he had some time.
I could do it, but I don't have much time either :p

1343
Lua / Re: Lua problems and bugs
« on: August 18, 2011, 05:49:42 am »
Why 3?
It was a cool way of fetching external data :/

1344
Lua / Re: Lua Classes
« on: August 18, 2011, 05:33:07 am »
I'm glad I could be of help :)

1345
Lua / Re: Lua problems and bugs
« on: August 18, 2011, 05:32:34 am »
Ah, didn't know it could be disabled. Thanks :)

1346
Lua / Re: Getting info from the local calc with Lua
« on: August 18, 2011, 05:31:36 am »
You can get the current locale using [lua]locale.name[/lua]. It will return the locale in a two letter language code :)

As for the battery info and the serial number, I don't think you can.

1347
Lua / Re: Lua Classes
« on: August 17, 2011, 03:18:57 pm »
Well, it really depends how you want to do it :)

First create the class and its init script. The init script for a button would set for example it label and size. Then you need to add an paint function to it, were you draw it.
Also, you should keep a table with references to all the buttons, so that you can link event to it.
Something like this:
Code: [Select]
--The table we keep all references to created buttons in
ButtonTable = {}

--Create the class
button = class()

--Create and init the button
function button:init(label, x, y, action)
    self.label = label
    self.x = x
    self.y = y
    self.action = action
    self.labelWidth = 0
    self.width = 0
    self.height = 20
    
    table.insert(ButtonTable, self)
end

--Draw the button
function button:paint(gc)
self.labelWidth = gc:getStringWidth(self.label)
self.width = self.labelWidth + 4
gc:setColorRGB(0,0,0)
gc:setFont("serif", "b", 12)

gc:drawRect(self.x, self.y, self.width, self.height)
gc:drawString(self.label, self.x+1, self.y+2, "top")
end

Well, but now you will wonder how to make it clickable and all.
Look at this full code:
Code: [Select]
--The table we keep all references to created buttons in
ButtonTable = {}

--Create the class
button = class()

--Create and init the button
function button:init(label, x, y, action)
    self.label = label
    self.x = x
    self.y = y
    self.action = action
    self.labelWidth = 0
    self.width = 0
    self.height = 20
    
    table.insert(ButtonTable, self)
end

--Draw the button
function button:paint(gc)
self.labelWidth = gc:getStringWidth(self.label)
self.width = self.labelWidth + 4
gc:setColorRGB(0,0,0)
gc:setFont("serif", "b", 12)

gc:drawRect(self.x, self.y, self.width, self.height)
gc:drawString(self.label, self.x+1, self.y+2, "top")
end

--What happens if you click the button
function button:click()
self.action()
end

--Check if clicked, and if clicked call its click method
function button:checkClick(x, y)
if y >= self.y and y <= self.y + self.height and x >= self.x and x <= self.x + self.width then
self:click()
end
end

--Check ButtonTable, and draw all the button in it
function drawButtons(gc)
for _, selectedButton in pairs(ButtonTable) do
selectedButton:paint(gc)
end
end


----------------------


--The on.create even. Here we create a sample button, and make that it will call testFunction when clicked
function on.create()
button1 = button("Test!", 100, 50, testFunction)
end


--TestFunction
function testFunction()
bclicked = true
platform.window:invalidate()
end

--The paint event
function on.paint(gc)
if bclicked then
gc:drawString("The button was clicked", 10, 10, "top")
end

drawButtons(gc)
end

--Link the click event to the buttons
function on.mouseDown(x, y)
for _, selectedButton in pairs(ButtonTable) do
selectedButton:checkClick(x, y)
end
end

This should explain most of it :)
Note that I didn't try this, so there might be some errors.

I strongly recommend you too look at the source of Adriweb's contest entry here: https://github.com/adriweb/Nspire-BreakOut .
Its a very good example of what you want to do, and should be easy to understand :)

EDIT:
Ok, tested it and fixed some bugs :) (Thanks Adriweb!)

1348
TI-Nspire / Re: My Nspire Contest Lua Entry : ImprovedSoloPong
« on: August 17, 2011, 09:36:24 am »
@Levak : Well, now he knows it, he will become more powerful than you >:D
You can't take knowledge away \o/

1349
Looks nice, good job :)

1350
TI-Nspire / Re: My Nspire Contest Lua Entry : ImprovedSoloPong
« on: August 17, 2011, 06:44:19 am »
I tried the fixed game, but in my opinion its to fast in the beginning.
Today I tried again, and it became acceptable. I really like the physics in the game, and you use OOP very well :)

Good job!

Pages: 1 ... 88 89 [90] 91 92 ... 125