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
31
« on: April 13, 2012, 12:07:16 am »
The function on.paint misses an END (you can see this fairly easy with notepad++). I added it, but all I can see is a blue screen...
I would also recommend (apart of indenting the code) is that since I saw several pieces of code that repeats, it should be good to identify them & create a function for them, like for example, the color picker.
Something like this could do:
function color_picker(gc, top) if top==0 then gc:setColorRGB(255*d,255*d,255*d) elseif top==1 then gc:setColorRGB(150*d,100*d,50*d) elseif top==2 then gc:setColorRGB(150*d,150*d,150*d) elseif top==3 then gc:setColorRGB(200*d,200*d,200*d) end end ^This can be optimized, but I think is ok for now...
This will make the code more legible
32
« on: April 11, 2012, 05:28:58 am »
33
« on: April 09, 2012, 04:05:48 pm »
Well, I've been reading some documentation regarding LUA & Nspire LUA, so I know it more or less. I would say like at intermediate level... As for projects, I recently remade a Nonogram program, that you can check on its topic: http://ourl.ca/15731
34
« on: April 08, 2012, 02:20:22 pm »
"action" was used to classify which actions can be performed when you press a key. I'm not sure if you intend to add more command actions (like flee, heal, steal, etc.), but if you do, you can now easily add them on the table. "state", behaves as a filter event. It keeps track of the action executed. Then you can control in your program what to do when something happened. "chance" was created to reduce the amount of lines. Since attack & defense behave alike, you can group them. I added the blank one just in case you want to create something like a "miss" or so. This is an ordered table, so when the variable r2 = 1, chance[r2] is the same as "successful . +" This link might be helpful for understanding more about how to use tables http://nixstaller.sourceforge.net/manual/0.2/nixstaller_9.html#Tables
36
« on: April 04, 2012, 08:52:28 pm »
I redefined some variables, I think is more legible this way:
--[[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]]--
chance = { [-1] = "", [0] = "unsuccessful . -", [1] = "successful . +" }
action = { nothing="", attack="Attack", defense="Defense"}
function initialize_variables() v = 0 t = 0 r1 = 0 r2 = -1 state = action.nothing 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 == action.attack then gc:drawString("Attack was " .. chance[r2] .. r1, 10, 50, "top") elseif state == action.defense then gc:drawString("Defense was " .. chance[r2] .. r1, 10, 50, "top") 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 = action.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 end
elseif ch=="d" then state = action.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 state=action.defense t=t+1 end
elseif ch=="r" then initialize_variables() end
platform.window:invalidate() end
function round(value, digits) return string.format("%." .. digits .. "f", value) end
37
« on: April 01, 2012, 04:01:20 pm »
NonogramNonograms, also known as Hanjie, Paint by Numbers, or Griddlers, are picture logic puzzles in which cells in a grid have to be colored or left blank according to numbers given at the side of the grid to reveal a hidden picture. In this puzzle type, the numbers measure how many unbroken lines of filled-in squares there are in any given row or column. Looking at pianoman's nonograms topic, I saw that the puzzles weren't that interesting, but it had potential to be improved. I remembered that I used to play on the Internet a flash version called TylerK's Picross game, until it was taken down (The word picross is a registered word by Nintendo AFAIK). This version includes a little over 30 puzzles with a size of 15x15. CONTROLS: DIRECTIONAL KEYS - Moves through the puzzle ENTER - fills a cell (you solve the puzzle with this one) BACKSPACE - crosses out a cell RETURN - marks a cell (just for guideline) CONTEXT MENU - opens the context menu ESC - closes the context menu TAB - starts a new level, randomly chosen c - checks the puzzle to see if is solved correctly or not h - hint r - resets the puzzle s - solves the puzzle p - picks the next puzzle There are a few things that could be improved, like creating a pop-up to choose the level, marking the already answered puzzles or even be able to create your own puzzles. I guess I'll consider those options if I decide to do a next version of this game... At last, I would like to give credits to TylerK, I used his puzzles to create the game. And pianoman, I re-coded his work to make it more versatile, thanks a lot EDIT: added control with the number keys (only on the LUA code, though)
38
« on: March 28, 2012, 11:30:47 am »
Concatenates two strings (joins them together into a single one)
Edit: So for the following code:
local str = Moves .. " moves" Moves is a variable that contains the number of times you've moved a piece " moves" is a string & remains the same
Let say Moves = 200, so the string is equivalent to: "200 moves"
39
« on: March 27, 2012, 10:26:33 pm »
% Stands for modulo (though it can have other uses too)
a % b == a - math.floor(a/b)*b
40
« on: March 27, 2012, 10:21:32 pm »
Did you tried increasing the contrast to see if it makes any difference?
The shortcut is ctrl + plus
41
« on: March 09, 2012, 11:14:30 am »
I know that there is no case switch statement in LUA (although there's a work-around explained here, which I never got it to work like I wanted). However, if you have an ordered list, you can use the following code: function equipment() --Define strings for current equipment --Helmet descriptions str_helm = {"Level 1 Leather Cap", "Level 2 Iron Guard", "Level 3 Mithril Helm", "Level 4 Mage Helm", "Level 5 3rd Age Helm", "Level 6 Ultimate Visage", "L3v31 7 L33t H31m"} curhelm = str_helm[helm]
--Armor descriptions str_armor = {"Level 1 Leather Body", "Level 2 Iron Mail", "Level 3 Mithril Plate", "Level 4 Enchanted Armor", "Level 5 3rd Age Armor", "Level 6 Champion's Plate", "L3v31 7 L33t P1@t3"} curarmor = str_armor[armor] --Sword descriptions str_sword = {"Level 1 Bronze Dagger", "Level 2 Iron Shortsword", "Level 3 Mithril Longsword", "Level 4 Godsword", "Level 5 3rd Age Greatsword", "Level 6 Great Broadsword", "L3v31 7 L33t D3s1r0Y3r"} cursword = str_sword[sword]
--Shield descriptions str_shield = {"Level 1 Wooden Guard", "Level 2 Iron Buckler", "Level 3 Mithril Square Shield", "Level 4 Mirror Shield", "Level 5 3rd Age Heraldic Shield", "Level 6 Champion's Kiteshield", "L3v31 7 L33t D3f3?d?r"} curshield = str_shield[shield]
--Robe descriptions str_robe = {"Level 1 Brown Robe", "Level 2 Grey Robe", "Level 3 Blue Robe", "Level 4 White Robe", "Level 5 Black Robe", "Level 6 Epic Robe", "L3v31 7 l33t r0b3"} currobe = str_robe[robe]
--Shoes descriptions str_shoes = {"Level 1 Leather Shoes", "Level 2 Iron Studded Boots", "Level 3 Mithril Studded Boots", "Level 4 Shoes of Light", "Level 5 3rd Age Runners", "Level 6 Boots of Lightness", "L3v31 7 L33t R?pp3rs"} curshoes = str_shoes[shoes]
--Ring descriptions if ring == 0 then cur_ring = "None" else if ring_sight == 2 then cur_ring = "Ring of Sight" elseif ring_fear == 2 then cur_ring = "Ring of Fear" elseif ring_train == 2 then cur_ring = "Training Ring" elseif ring_wealth == 2 then cur_ring = "Ring of Wealth" elseif ring_cure == 2 then cur_ring = "Ring of Curing" elseif ring_health == 2 then cur_ring = "Ring of Health" elseif ring_l33t == 2 then cur_ring = "L33t R1ng" end end --Bow descriptions str_bow = {"None", "Level 2 Oak Shortbow", "Level 3 Maple Bow", "Level 4 Righteous Longbow", "Level 5 3rd Age Horn Bow", "Level 6 Champion's Bow", "L3v31 7 L33t b0W"} curbow = str_bow[bow]
--Arrow descriptions if arrow_type == "normal" then cur_arrows = "Normal" elseif arrow_type == "fire" then cur_arrows = "Fire " elseif arrow_type == "poison" then cur_arrows = "Poison " elseif arrow_type == "ice" then cur_arrows = "Ice " elseif arrow_type == "magic" then cur_arrows = "Magic ?" elseif arrow_type == "light" then cur_arrows = "Light " else cur_arrows = "L33t " end end Skips some IF statements & reduce a couple of lines too... You could move the descriptions into the function on.create() so that you only create the description once (Or do the same thing you do with the image logo)... I didn't changed the Ring & Arrow descriptions since I'm not sure how you use them. Well, they could be reduced if you use a single array for all rings... At last, the function on.paint(gc) is getting a little to big, it would be good to split some parts into new functions, just remember to pass "gc" as a parameter: --Define the height and width of the screen to be used the rest of on.paint h = platform.window:height() w = platform.window:width()
function on.paint(gc) --Sets the initial font and color gc:setFont("sansserif", "b", 10) gc:setColorRGB(0, 0, 0) ---values used throughout on.paint() local string_h = gc:getStringHeight(line[1]) local pos_x = 0 local pos_y = 0 local shape_h = 0 local shape_w = 0 -----------------------------Intro Screen of the game----------------------------------------------- if mainMenu == 1 then intro(gc) ---With mainMenu = 0 and init = 0, it means we are out of the Title screen, but in the middle of initialization aka character select elseif mainMenu == 0 and init == 0 then ... end end
function intro(gc) --placing credits to superbany gc:setFont("sansserif", "b", 10) gc:drawString("Presenting Superbany's...", 4, 20) --placing credits to myself gc:setFont("sansserif", "b", 8) gc:drawString("Ported to Lua by Ghezra", w-gc:getStringWidth("Ported to Lua by Ghezra"), h) ... end
h & w are globals now. You could rather put them also inside the on.create() function & redefine them on the function on.resize() if you feel the screen size could change.
42
« on: March 08, 2012, 01:49:52 pm »
I see that you mention that the calculator has problems when you try to store +14 variable entries. I would suggest you sort the variables that belongs on the same category & store them together & don't group them like you currently do (though I guess is fine right now as to keep them in control)
BTW, you can also use arrays there. This is how the function savegame() could look
-------------------------------------------------------------------------------- function savegame() -------------------------------------------------------------------------------- --Current savegame process. Split up because the Nspire losses variables after 14 entries-- local game_save = {} game_save[1] = {race,arrows,arrowtyp,bag,bankgold,bomb,bow,boss1,boss2,boss3,boss4,burn,day,defboost} game_save[2] = {defense,potion_def,dexboost,potion_dex,dexterity,distance,enburn,enlife,enpois,game,gold,gotboss1,gotboss2,gotboss3} game_save[3] = {gotboss4,helm,herb,hp,hpmax,potion_hp,intboost,intelligence,potion_int,lamp,level,molotov,mp,mpmax} game_save[4] = {potion_mp,orb,points,poisdag,pois,ring,ringcure,ringfear,ringhealth,ringl33t,ringsight,ringtrain,ringwealth,robe} game_save[5] = {shield,shoes,skillretreat,skillrun,skillscan,speboost,special,speed,spellbolt,spellheal,spellstat,spellstun,potion_spe} game_save[6] = {strboost,strength,potion_str,stun,sword,xp,armor}
for i=1, 6 do var.store("save.game" .. i, game_save[i]) end
--Scan is already a table, so its just saved as a table var.store("save.game7", scan) end Note that I changed "savegame#" to "save.game#". These are called group variables, is just to keep similar variable together in a group called "save"
43
« on: March 07, 2012, 02:11:33 pm »
Nice to see there's activity again in this game I see that there is no color, I guess that was just something I was modifying (changed the text to have a blue color instead of black...) Also noticed that you don't use arrays, I highly recommend you to change the variables you use for the strings into arrays of strings. It should help a lot reducing the amount of code you have. Well, you should really use it when you have variables like foo1, foo2, etc. that are related each other... For example: Instead of talkLine1, talkLine2, etc., you can create a variable talkLine = {} and then call them like this talkLine[1], talkLine[2], etc. Here's a code example, so that you can see it easier: function on.create() initChoice = 1 showEquip = 0 showUp = 0 mainChoice = 1 magicSelect = 0 race = "Spirit" mainMenu = 1 init = 0 escMenu = 0 line = {} for i=1, 10 do line[i] = "" end
castleLine = {} for i=1, 4 do castleLine[i] = "" end
townLine = {} for i=1, 10 do townLine[i] = "" end
combatLine = {} for i=1,8 do combatLine[i] = "" end
upLine = {} for i=1, 8 do upLine[i] = "" end
talkLine = {} for i=1,5 do talkLine[i] = "" end platform.window:invalidate() --what else would be good to do as the program initializes? end
function on.paint(gc) ... for i=1,#talkLine do gc:drawString(talkLine[i], 5, 20+shm*(i-1)) end ...
44
« on: February 20, 2012, 06:20:24 pm »
I know that Irfanview has an option to change the color depth to 2 colors (1 bpp) & that you can apply the changes to multiple images. Though I'm not sure if is what you're looking for... Here's a page I found that mentions more or less how to do it: http://imslp.org/wiki/IMSLP:Image_Conversion
45
« on: February 10, 2012, 06:14:13 pm »
Yea, usually that's why topics become inactive, so I wanted to send a PM since I added some tweaks to the code & wouldn't knew if it bothered you or was ok. Anyway, keep it up epic7 & hope you can finish it soon
|