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 - 3rik
Pages: 1 ... 3 4 [5] 6 7 8
61
« on: January 11, 2012, 09:42:25 pm »
Hmmm... That's usually the problem with "attempt to index global 'coord' (a nil value)."
If everything is spelled and capitalized correctly and the coord = {} is in the correct spot then the error might be in a different part of the code.
Is coord defined in a function? If so, on.paint may be called before coord is initialized.
62
« on: January 11, 2012, 09:28:33 pm »
You may need a line to initialize coord as a table before you can index it in the for loops. Try adding this at the beginning: coord = {} Hopefully an easy fix.
63
« on: January 10, 2012, 12:00:10 am »
Thanks guys! Hey adriweb! I was looking through your optimized version and I found statements like
turn = (turns[2] == 1 and math.random() < .5) and "o" or "x" and
color = side == "x" and "Black" or "White" Could you explain how that works?
The statements adriweb wrote are idioms for Lua that take advantage of Lua's short circuit evaluation with logical operators to change the value of a variable without using if ... then ... else statements . Basically it follows the form: var = A and B or C
It has equivalent results as the following code: if A then var = B else var = C end
So if A is a true value then var = B and if A is a false value then var = C. The only condition for this to work properly is B must be a true value (not false or nil) or it may give unexpected results (unless, of course, you were expecting them). Great work with the AI so far and I hope you get the pause figured out soon. Would it be possible to split up the player and AI moves and have the AI wait for a signal from the timer to make the move?
64
« on: January 06, 2012, 11:18:22 pm »
If you have the choice between fillRect, fillArc, or fillPolygon and drawImage, I'd go with the fill functions. Obviously if you want some intricate pattern on the screen it is ridiculous to put hundreds of fillRects but if it is something relatively simple then it is usually a good choice. Personally I've only noticed a speed difference when there's a lot of images being drawn, however, images take up a bunch of memory compared to fillRect.
If you want to just draw a simple chess board you could do something like this:
function on.paint(gc) gc:setColorRGB(0, 0, 0) draw = false for column=1, 8 do draw = not draw for row=1, 8 do draw = not draw if draw then gc:fillRect(column * 25 - 19, row * 25 - 19, 25, 25) end end end gc:drawRect(5, 5, 201, 201) end
I'm not sure if I answered your question but I hope this helps.
65
« on: January 02, 2012, 09:50:52 pm »
I think by attaching it automatically shows the picture at the bottom as long as it has a common file extension. If you want to show it in a different part of the post you can modify your post and use the url of the attachment in [img] tags. For example [img]http://www.omnimaga.org/index.php?action=dlattach;topic=12110.0;attach=11007[/img] produces I wish you luck with your project. It looks like you have a great start.
66
« on: December 31, 2011, 11:14:23 pm »
Today I decided to make a progress bar for Lua Galaga.
67
« on: December 28, 2011, 12:52:07 am »
Hello everyone! I missed a lot of posts.
I was using a system much like the one adriweb was proposing. I have classes with all the necessary data and methods for each object type. Then when I create a new instance of the class, I store it to a table. When each missile moves, I check to see if it is touching any enemy object. If it is, a method is called which in this case, deletes both the enemy and the missile. In the future, it will probably trigger an explosion animation too.
The scrolling will be skippable. I just wanted to emphasize that this was a demo and not the final product yet.
I hope every one had a happy holiday season this year!
68
« on: December 24, 2011, 02:44:53 am »
This was meant to be just a simple test to demonstrate the shooting so that I knew it would work. I could have pressed enter sooner instead of waiting until the text stopped. It's kinda hard to tell because you can't see the keys I was pressing. Also, I can always adjust the speed that the text scrolls at too.
69
« on: December 24, 2011, 01:53:31 am »
This week we have finished the scrolling text class and, as of today, we have completed the basics needed for the player to shoot missiles. The timing isn't perfect yet but that will be fixed later. Here's an animated gif to see our progress: Thank you for your interest in our project.
71
« on: November 28, 2011, 12:18:44 am »
As far as I'm aware, commands that are usable by functions can be accessed using math.eval() but commands like Request and Text are only available in programs. Visit http://ourl.ca/12647 for more information. An example of the usage of math.eval is located here: http://www.inspired-lua.org/2011/08/save-a-high-score-without-cheating-possibility/math.eval(math_expression) This function sends an expression or command to the Nspire math server for evaluation. The input expression must be a string that the Nspire math server can interpret and evaluate. If the math server successfully evaluates the expression, it returns the numerical results. The eval function returns no result if the math server does not return a calculated result or if the calculated result cannot be represented as a fundamental Lua data type. If the math server cannot evaluate the expression because of a syntax, simplification, or semantic error, eval returns two results: nil and an error number.
72
« on: November 06, 2011, 12:37:35 pm »
When you start an Nspire Lua program, the calculator goes through the program and initializes any functions or variables and runs any instructions outside a function. Then it continues to loop through the event functions. In your example, when the program starts, on.enterKey() is initialized. When the enter key is pressed, the on.enterKey function is called. The on.paint function is defined here instead of having it be defined at the beginning. But the on.paint function is only called by the calculator when the window is "invalidated." The window starts out invalidated but becomes valid after the on.pain function is called. Moving the cursor or opening the catalog invalidates the screen and this is why your function works the way it does. To purposely invalidate the window (thus calling on.paint at the end of the current function) you can use the platform.window:invalidate() function. To summarize all this, here is code that accomplishes what you were trying to do. enterHasBeenPressed = false --initializes enterHasBeenPressed to be false function on.paint(gc) if enterHasBeenPressed then --exicute the following code if enterHasBeenPressed is true gc:drawString("Hello World", 0, 0, "top") end end function on.enterKey() enterHasBeenPressed = true --Since enter has been pressed enterHasBeenPressed is now true platform.window:invalidate() --invalidates the window so when on.enter is done on.paint will be called end
Having events being called takes a bit to get used to if you're used to a purely sequental language, but if you keep trying, you'll catch on. Also if you haven't already, introduce yourself here. Welcome to Omnimaga! Edit: Ninja'd I suppose enterHasBeenPressed doesn't actually need to be set to false at the beginning but explicitly telling it to be false is good for other humans reading it. Both ways work. Also remember that just because you've initialized a function, it doesn't mean it will be called. The special event functions (like on.paint) are tricky because in simple programs this seems to be the case.
73
« on: October 20, 2011, 06:29:53 pm »
That is awesome! I have always been annoyed by that.
74
« on: October 20, 2011, 05:11:11 pm »
javascript:void(0) is to prevent your browser from trying to load a new page when you click a link. It is used when you want something on the current page to happen. Juju's link on page one is an example of this. (I can't properly quote it.) It can also be useful in bookmarklets that affect the current page. <a href="javascript: void(0)">Link to Nowhere </a> This is basically a link that does absolutely nothing. For more information you can read this: http://www.tizag.com/javascriptT/javascriptvoid.php
75
« on: October 12, 2011, 07:01:09 pm »
Another cool bookmarklet: javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Search terms [leave selection and box blank to list all pages] ...").replace(/\s\+/g,"%252B");if(q!=null)location=" http://www.google.com/search?q="+q.replace(/\s+/g,"+")+"+site:"+location.hostname;void(0); It allows one to search sites that don't have search bars (or sites that have really bad search bars) using Google in an efficient way. Edit: From http://www.imilly.com/
Pages: 1 ... 3 4 [5] 6 7 8
|