Author Topic: Ti RPG 2 done in Lua (V0.06)  (Read 32267 times)

0 Members and 1 Guest are viewing this topic.

Offline Ghezra

  • LV2 Member (Next: 40)
  • **
  • Posts: 30
  • Rating: +4/-0
    • View Profile
Re: Ti RPG 2 done in Lua (V0.04a)
« Reply #45 on: March 07, 2012, 06:41:30 pm »
Question on loadstring.. So its a function that runs a string as if it were an instruction line.. but I can't seem to get it to work right.

Here is a simple example of what I have:

This is what I think it should do, potpt("mp", "mpmax", "mppotion"), then goes into the potpt function,
the first loadstring should be

loadstring(potstr.." = "..potstr.." - 1")()

which string wise would be

loadstring("mppotion = mppotion - 1")()

so it should run the line:

mppotion = mppotion - 1

But it doesn't. Where am I going wrong with my use of loadstring? Any suggestions?

Code: [Select]
...
     potpt("mp", "mpmax", "mppotion")
...

function potpt(statstr,statmaxstr,potstr)
boostamt = 0
loadstring(potstr.."="..potstr.."-1")()
boostamt = math.random(1,dexterity)
loadstring(statstr.."="..statstr.."+boostamt")()
if loadstring("if "..statstr..">"..statmaxstr.." then return true")() then
loadstring(statstr.."="..statmaxstr)()
end
combatLine1 = "You drink an "..statstr.." potion... +"..boostamt.." "..statstr.."."
end

Offline cyanophycean314

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 363
  • Rating: +43/-1
  • It's You!
    • View Profile
Re: Ti RPG 2 done in Lua (V0.04a)
« Reply #46 on: March 07, 2012, 08:09:56 pm »
Hmm. Never heard of loadString, but it sounds really nice. Will research.

Offline Ghezra

  • LV2 Member (Next: 40)
  • **
  • Posts: 30
  • Rating: +4/-0
    • View Profile
Re: Ti RPG 2 done in Lua (V0.04b)
« Reply #47 on: March 08, 2012, 12:09:18 am »
Potions completed, I just bypassed the use of 'loadstring' altogether even though it kept the code cleaner. If it don't work I can't use it! lol

Also added in a smattering of color (only three things) But for those of you with the CX's, it will be slightly cooler looking.

*Edit: PS: New source and TNS file put on main post, as always.


« Last Edit: March 08, 2012, 12:09:50 am by Ghezra »

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: Ti RPG 2 done in Lua (V0.04b)
« Reply #48 on: March 08, 2012, 02:07:20 am »
Great suggestion id have 2 say, someone!
@gherza it's good 2 see you respond so quickly and that you're making it look good in all colours!
« Last Edit: March 08, 2012, 07:43:06 am by Jonius7 »
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Ti RPG 2 done in Lua (V0.04b)
« Reply #49 on: March 08, 2012, 03:11:21 am »
About the number case on the previous page, you can also do
if tonumber(char) then
  your code
end

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: Ti RPG 2 done in Lua (V0.04b)
« Reply #50 on: March 08, 2012, 07:45:06 am »
Good to see the source code attached as a .lua file. It was a bit of a hassle trying to copy the text from the code box as somehow pressing copy to clipboard didn't work and I had to select all, copy and paste it to view it manually.
And also yay! Health bars in the right sidebar makes it much better and more consistent.
« Last Edit: March 08, 2012, 07:46:04 am by Jonius7 »
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Offline Ghezra

  • LV2 Member (Next: 40)
  • **
  • Posts: 30
  • Rating: +4/-0
    • View Profile
Re: Ti RPG 2 done in Lua (V0.04b)
« Reply #51 on: March 08, 2012, 11:41:44 am »
I added the ability to Run and to scan the enemy.

But some minor/major bugs cropped up so I'm going to wait till tonight to squash them a little bit before releasing a new version. I know the game won't be entirely playable until equipment/items get sorted. But as it stands right now Superbany programmed the equipment store in such a way that its almost entirely unusable in Lua. So I'll be redesigning it from scratch like I did with the level up screen.

I'll keep working on it everyday and make it better and better.

Offline someone

  • LV3 Member (Next: 100)
  • ***
  • Posts: 49
  • Rating: +9/-0
    • View Profile
Re: Ti RPG 2 done in Lua (V0.04b)
« Reply #52 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
Code: [Select]
--------------------------------------------------------------------------------
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"

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Ti RPG 2 done in Lua (V0.04b)
« Reply #53 on: March 08, 2012, 02:07:17 pm »
You can also save progress by returning a table in on.save().
The nspire will then give it as argument to on.restore when you open the program next time.

Offline Ghezra

  • LV2 Member (Next: 40)
  • **
  • Posts: 30
  • Rating: +4/-0
    • View Profile
Re: Ti RPG 2 done in Lua (V0.04b)
« Reply #54 on: March 08, 2012, 02:38:14 pm »
I made the array changes to the save and load functions. It all works without any problems.

As far as grouping goes.. I never thought to group the save because well, The only reason I need them grouped at all is just so they save correctly in groups of 14. The grouping they exhibit is never functionally used at all. So I think I'll leave them grouped as such as it doesn't particularly matter.

What I did notice however is how you have variables 'group' grouped.
ie: potion_hp potion_mp potion_dex potion_int etc etc
Why use _ instead of . here? Which is the better syntax wise? I'm all for changing. I'm going back now to see about doing the strings in arrays for the displays.

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Ti RPG 2 done in Lua (V0.04b)
« Reply #55 on: March 08, 2012, 02:47:17 pm »
_ is indicating just a variable name (hello_world) is a variable,
hello.world is like : hello is a table and world an object of this table.
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Ghezra

  • LV2 Member (Next: 40)
  • **
  • Posts: 30
  • Rating: +4/-0
    • View Profile
Re: Ti RPG 2 done in Lua (V0.04b)
« Reply #56 on: March 08, 2012, 02:59:12 pm »
Ahh thanks for the clarification. Also so far the arrays of strings are working nicely. Compacting code a bit. As can be seen by the new combatLineCycle()

I also am making everything agree with that naming convention. (which is pretty easy with "find 'dexpotion, replace all with 'potion_dex' lol)

Code: [Select]
function combatLineCycle()
for i=1,7 do
combatLine[9-i] = combatLine[8-i]
end
end

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Ghezra

  • LV2 Member (Next: 40)
  • **
  • Posts: 30
  • Rating: +4/-0
    • View Profile
Re: Ti RPG 2 done in Lua (V0.04b)
« Reply #58 on: March 08, 2012, 04:02:35 pm »
Jim, don't think I didn't see what you said. It was great!! Now the save game is completely nested inside the Lua so no chance of cheating!! Great ideas everyone! This is so helpful, lol


EDIT: Adri! You snuck in right as I posted! Thanks for showing me that, Jim had mentioned it before, it was THAT website actually that I used as a guide for how I changed my code.

Code: [Select]
function on.save()
game_save = {}
game_save[1] = {race,arrows,arrowtyp,bag,bankgold,bomb,bow,boss1,boss2,boss3,boss4,burn,day,boost_def}
game_save[2] = {defense,potion_def,boost_dex,potion_dex,dexterity,distance,en_burn,en_life,en_pois,game,gold,gotboss1,gotboss2,gotboss3}
game_save[3] = {gotboss4,helm,herb,hp,hpmax,potion_hp,boost_int,intelligence,potion_int,lamp,level,molotov,mp,mpmax}
game_save[4] = {potion_mp,orb,points,poisdag,pois,ring,ring_cure,ring_fear,ring_health,ring_l33t,ring_sight,ring_train,ring_wealth,robe}
game_save[5] = {shield,shoes,skill_retreat,skill_run,skill_scan,boost_spe,special,speed,spell_bolt,spell_heal,spell_stat,spell_stun,potion_spe}
game_save[6] = {boost_str,strength,potion_str,stun,sword,xp,armor}
game_save[7] = scan
return game_save
end
function on.restore(save)

local game_load1 = save[1]
local game_load2 = save[2]
local game_load3 = save[3]
local game_load4 = save[4]
local game_load5 = save[5]
local game_load6 = save[6]

if game_load1 == nil then
--Then there is no save game and it displays as such
else
race = game_load1[1]
armor = game_load6[7]
arrows = game_load1[2]
...etc..
end
end
« Last Edit: March 08, 2012, 04:05:26 pm by Ghezra »

Offline Ghezra

  • LV2 Member (Next: 40)
  • **
  • Posts: 30
  • Rating: +4/-0
    • View Profile
Re: Ti RPG 2 done in Lua (V0.04c)
« Reply #59 on: March 08, 2012, 05:47:14 pm »
**And having been working on this relatively constant for the last 4-5 days, I'm going to take a day long breather. Step back from the code a bit. Keep the great suggestions coming!**


-----------------------
Update:
Newest version is runnable. 0.04c 3/8/2012.

Combat options like Run, Retreat, Scan now work as intended
But you'll have to wait until you get them through leveling up.
Run - lvl 5
Scan - lvl 10
Retreat - lvl 15
Huge revisions to the lua code, namely the Save and load games and incorporation of string arrays.


Next 3 on list to finish:
-Code modification/clarity
-Item store
-Armor store
-----------------------
« Last Edit: March 08, 2012, 05:48:44 pm by Ghezra »