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 - someone
16
« on: September 05, 2012, 07:21:02 pm »
The difference between colon ( : ) and dot ( . ) is that the former one pass "self" as the first parameter.
So, platform.window:invalidate() should be equivalent to platform.window.invalidate(platform.window) & that's why is saying that the first argument is wrong on the image you posted.
17
« on: September 04, 2012, 08:07:00 pm »
Hey annoyingcalc, here are some suggestions I have to make the code more legible & easier to modify that you might find useful:
-- IMAGES -- backSRC = ... duckAliveSRC = ... duckDeadSRC = ... dogSRC = ...
img_dog = image.new(dogSRC) img_duckAlive = image.new(duckAliveSRC) img_duckDead = image.new(duckDeadSRC) img_background = image.new(backSRC)
-- CONSTANTS -- duck = { h = image.height(img_duckAlive), -- 30 px w = image.width(img_duckAlive) -- 37 px } inc = 5 -- image movement increment bg_gap = 50 -- background gap in coord X
function init() dx = 100 dy = 50 alive = 1 x = 0 y = 0 end
init() function on.paint(gc) cursor.set("translation") cursor.show()
-- Paint background gc:setColorRGB(0, 0, 0) gc:fillRect(0, 0, ww, wh) gc:drawImage(img_background, bg_gap, 0) if alive==1 then gc:drawImage(img_duckAlive, dx, dy) gc:drawImage(img_duckAlive, dx, dy) else if dy+duck.w <170 then gc:drawImage(img_duckDead, dx, dy) else gc:drawImage(img_dog, 150, 110) end end AI() end
function on.resize(width, height) ww = width wh = height end
function on.mouseDown(x, y) if between(dx, x, dx+duck.w) and between(dy, y, dy+duck.h) then shot() else miss() end end
function between(a, x, b) -- Checks if "x" is between range [a,b] if a <= x and x <= b then return true else return false end end
function AI() --place your Artificial Intelligence code here if alive==1 then if direction==1 then dx = dx-inc dy = dy-inc else dx = dx+inc dy = dy+inc end if dx==bg_gap then direction=1 end if dy >= wh then direction=0 end elseif dy+duck.w < 170 then dy = dy+inc end end
function shot() alive=0 end
function miss() -- Determine what happens if you missed a shot end
function on.escapeKey() init() platform.window:invalidate() end I skipped the code with the image source since is to large & wasn't modified... Here's what I did & why:
I see you made some comparisons with numbers 30 & 37, I assume this is the width & height of the image, that's why I set it to calculate it first & use them through a variable.
variable inc is the increment of how the duck moves. Is good to create a variable & change it at the top if you want it to modify later or in order to test different values.
bg_gap is the gap you left for the background. I don't know why 50, since 30 would be centered, so I leaved it there.
function init() was created in order to initialize everything, I used the key "esc" to call it. Useful to test everything from scratch w/o running or reopening the script. (if you want to use esc for something else, is easy to set it to any other key, though with a different function)
Created function "between" to make it easier to read when comparing where you shot (and renamed functioned used to a more informative one)
BTW, I see that you haven't checked the boundaries of the screen yet (and the way is currently determined is wrong). Maybe it would be better to determine where the duck is going to move next splitting the coordinates x & y.
18
« on: September 03, 2012, 07:29:57 pm »
Then, instead of using the function on.arrowKey(arrow), create one where you calculate the move, e.g:
function AI() --place your Artificial Intelligence code here
--if direction==1 then --dx=dx-1 --dy=dy-1 --else --dx=dx+1 --dy=dy+1 --end --if dx==0 then --direction=1 --end --if dy==240 then --direction=0 --end end
BTW, I see that you use an image from the NES & since the resolution is smaller, it will look awkward, so I would suggest to draw the rest of the background, this code would do:
function on.resize(width, height) ww = width wh = height end
function on.paint(gc) -- Paint background (sky) gc:setColorRGB(96, 176, 248) gc:fillRect(0, 0, ww, wh) -- Paint floor (dirt) gc:setColorRGB(104, 104, 0) gc:fillRect(0, 175, ww, wh-175) gc:drawImage(background,0,0) gc:drawImage(duck,dx,dy) AI() end Maybe you'll want to place drawing the duck image inside the AI() function, because if you're going to move the image a lot, it will look like it warps. So, you'll need to add the parameter "gc"
function on.paint(gc) ... AI(gc) end
function AI(gc) gc:drawImage(duck,dx,dy) end
19
« on: August 21, 2012, 08:32:07 pm »
They are the last 4 digits of the calculator's product ID
You can find the whole digits if you go to Home -> Settings -> Status -> About
20
« on: August 09, 2012, 03:37:35 pm »
How did you get the source from my .tns ?
You can now see the LUA code of the files if you use the latest version for the computer (Guess any version is fine). Is under the menu Insert -> Script Editor -> Edit Script Do you add a highscore or a 2 player mode?
I don't know about the high-score, but 2 player is in his todo list To do list : - Implementing the rules - Managing two players - Artificial Intelligence ! - Menu and all that graphic and GUI stuff..
21
« on: August 06, 2012, 06:59:01 pm »
ok, a quick review:
pressing '.' throws an error making the word 'it' and 'me' throws an error (probably all words with two letters, line 211: attempt to perform arithmetic on a nil value) i think you have to be too fast to make the words, maybe slow it down a little after a couple of seconds you list of made words disappears, but it does not return to the start or something, it just clears, which is kinda weird..
the timer is still at 1:30
otherwise it's very nice i love it
You can change the time inside the function on.timer, just change the if timepassed > 30000 to 120000 & you'll have the 2 minutes you're supposed to have. I also got an error, but it was on line 212, when it should be painting the path of the text selected, if I'm not mistaken.
22
« on: June 29, 2012, 02:33:30 pm »
Seems like the problem is on the function "string.sub". It might not be loading it when you open the file or something.
23
« on: June 26, 2012, 03:42:59 pm »
what coins should you enter a store with so that sum of the number of coins you enter a store and leave a store with is at a minimum?
The general idea here is that you basically want to carry the least amount of change. So, the way this works, is you pick E number of coins to enter with, after buying your items (which have random number of cents) you leave with L number of coins. You want to minimize L + E.
Rules:
- We're using American coins, so the choices are: penny - .01, nickel - .05, dime - .10, quarter - .25 (no half dollars, too rare )
- The number of cents your purchase costs is random (So, a purchase would cost some dollar amount + [0 - 99] cents)
- You receive the minimum number of coins from the cashier ($.90 is not 9 dimes)
Have at it. You'll of course have to provide some sort of justification for your answer.
I'm not sure I get the question right or not (and all the rules). Are you asking which coins you should bring for any situation? (in which the cost of the purchase varies from 0 to 99 cents, excluding round numbers which you can therefore use bills). If so, then you would you be able to use dollars. Because it would be useful to use them when the price is between 51¢ & 99¢, because then you would only need to calculate from 0¢ to 50¢, because the other part is just the complement (e.g. 66¢ = $1 - 34¢, so you calculate over 34¢ & not the 66¢). I was bored, so I was playing around with an Excel sheet & count that at most you would need for all & any case the following coins: 3 pennies 1 nickel 2 dimes 2 quarters However, if the question is just which is the worst of the cases, then you'll need to bring 5 coins at most, but it varies depending on the case...
24
« on: June 26, 2012, 12:19:20 am »
So, no one likes to carry around change (coins) and my question is, what coins should you enter a store with so that sum of the number of coins you enter a store and leave a store with is at a minimum?
The general idea here is that you basically want to carry the least amount of change. So, the way this works, is you pick E number of coins to enter with, after buying your items (which have random number of cents) you leave with L number of coins. You want to minimize L + E.
Rules:
- We're using American coins, so the choices are: penny - .01, nickel - .05, dime - .10, quarter - .25 (no half dollars, too rare )
- The number of cents your purchase costs is random (So, a purchase would cost some dollar amount + [0 - 99] cents)
- You receive the minimum number of coins from the cashier ($.90 is not 9 dimes)
You enter with no coins & you leave with no coins, and that is the least amount of change you have to bring. If you want to buy something, use a credit card ;)
25
« on: June 13, 2012, 06:33:43 pm »
This link should help: LUA Performance
27
« on: May 22, 2012, 05:33:11 pm »
Well, here's a version I put together with some sprites. It looks pretty nice, but the program runs noticeably slower... Any ideas on making it faster?
This page might be able to help you making it a bit faster by changing some parts of the code: http://trac.caspring.org/wiki/LuaPerformance
28
« on: April 19, 2012, 11:56:37 pm »
There are 2 ways to get out of PTT mode:
Get another device & connect them together, then go to My Documents & under the menu options there's one that lets you exit this mode.
If you don't have another device or that cable, then you can connect it to the computer & send a file named "Exit Test Mode" (is CASE sensitive, so beware of that), which you must send inside the "Press-to-Test" folder
29
« on: April 16, 2012, 11:16:18 am »
Well, I agree that the first part was a little abstract, so I removed it.
If you have any question on this code, be free to ask.
--[[Things to do: Declare variables first within a function Make things more fun and complex Points System: OLD: Atk -{1,2,3} +{4,5} Def +{1,2,3} -{4,5} NEW: Atk -{4,5} +{4,5} Def +{1,2,3} -{1,2,3} Any better ways? Maybe make Atk more risky, so it's less about luck]]--
-- Call this function whenever you want to set the variables to their original values function initialize_variables() v = 0 t = 0 r1 = 0 r2 = -1 state = "" end
--function on.create() initialize_variables() --end
function on.paint(gc) gc:setFont("sansserif","r",11) gc:setColorRGB(0,0,0) gc:drawString("[A]tk or [D]ef? [R]eset",10,10,"top") gc:drawString(v,10,30,"top")
if state == "attack" then if r2 == 1 then gc:drawString("Attack was successful . + " .. r1, 10, 50, "top") else --if r2 == 0 then gc:drawString("Attack was unsuccessful . -" .. r1, 10, 50, "top") end elseif state == "defense" then if r2 == 1 then gc:drawString("Defense was successful . + " .. r1, 10, 50, "top") else --if r2 == 0 then gc:drawString("Defense was unsuccessful . -" .. r1, 10, 50, "top") end end
gc:drawString("Turn " .. t,200,10,"top") if v~=0 or t~=0 then gc:drawString("Average " .. round(v/t,2), 200, 30, "top") end gc:setFont("sansserif","r",8) gc:drawString("Numstrat - Jason Ho",10,200,"top") end
function on.charIn(ch) if ch=="a" then state = "attack" r1=math.random(4,5) r2=math.random(0,1) if r2==1 then v=v+r1 else --if r2==0 then v=v-r1 end t=t+1
elseif ch=="d" then state = "defense" r1=math.random(1,3) r2=math.random(0,1) if r2==1 then v=v+r1 else --if r2==0 then v=v-r1 end t=t+1
elseif ch=="r" then initialize_variables() end
platform.window:invalidate() end
--This function rounds the value passed depending on the number of digits needed function round(value, digits) return string.format("%." .. digits .. "f", value) end
30
« on: April 13, 2012, 05:33:12 pm »
I got a crash when using the click button, it throws an error on the function on.mouseDown(x,y) on the last conditional (IF)
|