Rockbox Technical Forums

Rockbox Development => Starting Development and Compiling => Topic started by: HolyRoller on March 20, 2019, 02:18:50 PM

Title: Want to create a random generator for RPGs, how should I start?
Post by: HolyRoller on March 20, 2019, 02:18:50 PM
Hey guys!  I'm thinking what I want to do shouldn't be too difficult.  I simply want to program some random table generators for use with tabletop RPGs.  For example, when I click on Monster Generator, it will pick a number from 1-100, and then list the name for the corresponding monster to that number.  That's pretty much it, just a list of tables, I click on one, and it spits out the name.  Where should I start?  Is there something similar I can build on top of?  Let me know if you need more info, thanks!
Title: Re: Want to create a random generator for RPGs, how should I start?
Post by: Bilgus on March 20, 2019, 05:16:14 PM
Lua would be the easiest way to do this in Rockbox

https://www.rockbox.org/wiki/PluginLua
Title: Re: Want to create a random generator for RPGs, how should I start?
Post by: HolyRoller on March 22, 2019, 10:24:36 PM
Alright so I wrote a simple LUA script to print a random number, and my Clip freaks out when I try to open it.  This is the code:

math.randomseed(os.time())
print("Challenge Die: " .. math.random(1,10))

Am I missing formatting?
Title: Re: Want to create a random generator for RPGs, how should I start?
Post by: HolyRoller on March 22, 2019, 11:36:06 PM
Update: I was able to sort of get it to work, here is my code:

function print(message, seconds)
    rb.splash(seconds, message)
end

print(("Challenge Dice: %d"):format(math.random(1,10)), 5)

So it shows me the result of a die roll, but it flashes on the screen for a split second and closes.  Is there a way I can keep the result on the screen until I back out?
Title: Re: Want to create a random generator for RPGs, how should I start?
Post by: Bilgus on March 23, 2019, 09:33:29 AM
sleep(rb.HZ*Seconds) would be the easiest way

I have quite a bit of sample code in the plugins section that will probably help
http://forums.rockbox.org/index.php/board,27.0.html


Print API list:
http://forums.rockbox.org/index.php/topic,51935.0.html
Title: Re: Want to create a random generator for RPGs, how should I start?
Post by: HolyRoller on March 23, 2019, 12:33:55 PM
function print(message, seconds)
    rb.splash(seconds * rb.HZ, message) -- rb.HZ == 100
end

print(("Challenge Dice: %d"):format(math.random(1,10)), 5)

Ok I have made some progress, this code works.  Now I just want to show the result of multiple dice rolls in the same splash screen.  How would I go about doing that?  Do you recommend a similar plugin I could view?