|
#1
|
||||
|
||||
|
I would like to have a thread where programmers could post their questions, and those with more experience, etc... might answer. I think I'll begin.
Q1: Can I attach a Lua script named "functions", for example, to "main.lua", so that I could call any of the functions in the attached script from "main"? Q2: Does Lua support OOP programming? Could I declare class "tree" and, within it, function "new", and then call it "tree.new();"? Thanks! |
| Advertisement | [Remove Advertisement] |
|
|
|
|
#2
|
|||
|
|||
|
A1: Yes.
A2: Technically, no. It can be fudged though.
__________________
Only ONE more functions in the Wiki need addressing! Zen X-Fi2 LUA Wiki Want to protect your applications? Click Here! Tower Defense Thread Zen Lock - Protect Your Zen! |
|
#3
|
||||
|
||||
|
There is already a FAQ thread stickied, but maybe this Q&A is a little different..
Quote:
I don't know about your second question.. |
|
#4
|
||||
|
||||
|
I understand that some programmers are quite used to OOP, but imho there is nood need for OOP in LUA due to the low complexity of the apps that the Zen could actually handle.
__________________
Zen X-Fi2 Apps: Notee-fi (notepad) | TicTacToe | Mahjongg http://www.starfare.eu/ - a free real-time strategy game. |
|
#5
|
||||
|
||||
|
I think we can keep this thread together with the regular FAQ, here we might find more things to add to that thread via discussions and questions, and not have to clutter the FAQ thread with unnecessary posts.
__________________
"If you are good enough at English to apologize, then there is no need to." - A good friend of mine Discovered something about the X-Fi2 you think others may not know? Post it here so others can learn about it! Have a question about X-Fi2 apps? Consult the FAQ before creating a thread about it. Like my work? Tell your friends. Don't like it? Tell me so I can improve. ^.^ |
|
#6
|
||||
|
||||
|
Q1: I read at the X-Fi2/Lua wiki that math.random() returns a float. Is this true even if I provide arguments such as math.random(1,20)?
|
|
#7
|
||||
|
||||
|
A1: I believe it always returns a float, yes. Not that I myself differ much between the different kinds of numerical storage in the LUA language. I only say "number = 3" and that's that. Then I can set it to a Random or whatever later.
__________________
"If you are good enough at English to apologize, then there is no need to." - A good friend of mine Discovered something about the X-Fi2 you think others may not know? Post it here so others can learn about it! Have a question about X-Fi2 apps? Consult the FAQ before creating a thread about it. Like my work? Tell your friends. Don't like it? Tell me so I can improve. ^.^ |
|
#8
|
||||
|
||||
|
Q: Can the same table hold values with different data types?
|
|
#9
|
|||
|
|||
|
Quote:
Quote:
__________________
Only ONE more functions in the Wiki need addressing! Zen X-Fi2 LUA Wiki Want to protect your applications? Click Here! Tower Defense Thread Zen Lock - Protect Your Zen! |
|
#10
|
||||
|
||||
|
Things like this would be great to have in the X-Fi2 LUA wiki so it is easily findable for beginners. So this together with the modulo operator and similar things could be handy to have in a little section.
__________________
"If you are good enough at English to apologize, then there is no need to." - A good friend of mine Discovered something about the X-Fi2 you think others may not know? Post it here so others can learn about it! Have a question about X-Fi2 apps? Consult the FAQ before creating a thread about it. Like my work? Tell your friends. Don't like it? Tell me so I can improve. ^.^ |
|
#11
|
|||
|
|||
|
Reason I didn't was because I wanted to have only X-Fi2 information on that page only. That's why I linked to the full LUA manual.
__________________
Only ONE more functions in the Wiki need addressing! Zen X-Fi2 LUA Wiki Want to protect your applications? Click Here! Tower Defense Thread Zen Lock - Protect Your Zen! |
|
#12
|
||||
|
||||
|
What exactly does the touch.move() function do? If I have a game with a background map which the user navigates by clicking and dragging, would I have to put touch.move() within a loop so that the screen continually updates as the user's finger moves, or does it take care of this for me?
|
|
#13
|
||||
|
||||
|
Quote:
__________________
this is a link to my personal homepage which I haven't |
|
#14
|
||||
|
||||
|
Quote:
__________________
"If you are good enough at English to apologize, then there is no need to." - A good friend of mine Discovered something about the X-Fi2 you think others may not know? Post it here so others can learn about it! Have a question about X-Fi2 apps? Consult the FAQ before creating a thread about it. Like my work? Tell your friends. Don't like it? Tell me so I can improve. ^.^ |
|
#15
|
||||
|
||||
|
Thanks! Just a little more specific, does touch.move() contain it's own loop so that everything inside repeats until touch.move() is no longer 1? For example:
Code:
if touch.move() == 1 then newX,newY = touch.pos(); viewX += newX; viewY += newY; screen.update; end |
|
#16
|
||||
|
||||
|
Well it doesn't loop by itself or something, but since touch.move() should be called in the whole control.read() thingy in your main loop, the code you quoted will repeat until touch.move() is no longer 1. Besides, none of the touch.events will get a value if you don't call control.read() and control.isTouch() first, so you can't use touch.move() by itself. I like think of this as the "1" is pushed through to the appropriate event; first control.read is one, then isTouch becomes one, and then the event.
Note that using touch.move() may cause delay, because there is a lot (too much) of screen-input send to the app when you move and everytime it has to do the calculations. You may notice a lag on the player, and if you do, you can eliminate some screen-input by doing for i=0, 100 do control.read() end just before the end in the code you quoted. This erases 100 screen-inputs everytime to smoothen things up. Oh and I have a question for you, I see many people posting codes using things like your viewX += newX, but everytime I try "+=" to add stuff to a value, it gives me errors.. does it work for you?
__________________
this is a link to my personal homepage which I haven't Last edited by Brett_val; 09-14-2010 at 02:08 PM. |
|
#17
|
||||
|
||||
|
I was just testing something from my Colonization game when I read your last post. The simulator did indeed give me errors on +=.
|
|
#18
|
||||
|
||||
|
So I was testing my Colonization game, and I was getting this mysterious error when I tried the following:
Code:
screen.fillrect(XYtoUV(20, 20, 60, 60), green); |
|
#19
|
||||
|
||||
|
I don't think you can do that.. - the function returns to a stack local to that function call. So calling another function with it would just push that whole stack onto one memory block of the new stack.. (i think.. :P)
One way you could get round it is to redefine the screen.drawrect function to work in iso.. or define a new one that converts it and then calls the regular one
|
|
#20
|
||||
|
||||
|
Thanks! Also, someone noted that drawing an image at less than 0,0 caused the player to crash, so I'm trying to get around it by drawing only the part of that image which is visible on screen. exampleImage:draw(0, 0, 40, 40, 80, 80), which is supposed to just draw part of an image, doesn't seem to do anything; when I use it, no image is drawn. Do we know that this function actually works?
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 01:58 AM.












Linear Mode
