This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Zenon's profile picture

EnderDice! A Simple Dice Roller *Updated To Beta V2.0*

Started by Zenon, 19 July 2015 - 12:31 AM
Zenon #1
Posted 19 July 2015 - 02:31 AM
Hi All! This is a simple dice rolling program I whipped up that allows you to roll whatever dice you want.
Updated to Beta V2.0

Screenshots!
SpoilerNo Input:

After Dice Roll:

While Choosing Color:

After Choosing (I Choose Blue In This Pic):

The code can be found Here
And here:
Spoiler

--------------------------------------------------
--API Load--
file = fs.exists("themccm")
if file == false then
fs.makeDir("themccm")
end
file = fs.exists("themccm/enderapi")
if file == false then
shell.run("pastebin", "get", "5ww6Pb8i", "themccm/enderapi")
end
os.unloadAPI("themccm/enderapi")
os.loadAPI("themccm/enderapi")
--------------------------------------------------
--Color Loading--
file = fs.exists("themccm/enderdice")
if file == false then
fs.makeDir("themccm/enderdice")
end
file = fs.exists("themccm/enderdice/textcolor")
if file == false then
colorfile = fs.open("themccm/enderdice/textcolor", "w")
colorfile.writeLine("red")
colorfile.close()
end
colorfile = fs.open("themccm/enderdice/textcolor", "r")
textcolor = tostring(colorfile.readLine())
colorfile.close()
--------------------------------------------------
--Functions--
function introPrint()
print[[
Enter 'help' For A List Of Commands
What Dice Do You Want To Roll? -In Numbers-]]
term.write("Roll A d")
end
--------------------------------------------------
--Clear--
enderapi.clear()
--------------------------------------------------
--Visuals--
term.setTextColor(colors.lime)
print[[
--------------------------------------------------]]
term.setTextColor(colors.purple)
print[[
	 ----								 ----
	/ 20 \	--------------------	   / 20 \
	\ 20 /   /Welcome To EnderDice\	  \ 20 /
	 ----	|For Your Dicey Needs|	   ----
	 ----	\ Made By: theMCcm   /	   ----
	/ 10 \	--------------------	   / 10 \
	\ 10 /							   \ 10 /
	 ----		  Beta  V2.0			 ----]]
term.setTextColor(colors.lime)
print[[
--------------------------------------------------]]
if colors[textcolor] then
term.setTextColor(colors[textcolor])
end
introPrint()
--------------------------------------------------
--Main Code--
while true do
input = read()
inp = tonumber(input)
if type(inp) == "number" then
if inp < 1 then
term.clearLine()
print("Sorry, But Dice Need To Be Atleast One-Sided!")
elseif inp > 100000000000 then
term.clearLine()
print("That Would Crash The Program! Try A Smaller Number")
else
dice = math.random(input)
term.clearLine()
print("You Rolled A d"..inp.." And Got "..dice)
end
enderapi.lineUp()
enderapi.lineUp()
term.clearLine()
term.write("Roll A d")
else
if input == "exit" or input == "Exit" or input == "E" or input == "e" or input == "EXIT" then
  enderapi.clear()
  break
elseif input == "help" or input == "h" or input == "Help" or input == "H" or input == "HELP" then
  enderapi.lineUp()
  term.clearLine()
  term.write("Roll A d")
  enderapi.lineDown()
  enderapi.lineDown()
  print[[
Type 'Exit' To Exit (Duh :P/>/>/>/>/>/>/>)
Type 'Color' To Change Text Color]]
  enderapi.lineUp()
  enderapi.lineUp()
  enderapi.lineUp()
  enderapi.lineUp()
  term.write("Roll A d")
elseif input == "color" or input == "c" or input == "Color" or input == "C" or input == "COLOR" then
  enderapi.lineUp()
  term.clearLine()
  term.write("Pick A Color: ")
  textcolor = read()
  if colors[textcolor] then
  term.setTextColor(colors[textcolor])
  colorfile = fs.open("themccm/enderdice/textcolor", "w")
  colorfile.writeLine(textcolor)
  colorfile.close()
  end
  term.clearLine()
  enderapi.lineDown()
  term.clearLine()
  enderapi.lineDown()
  term.clearLine()
  enderapi.lineUp()
  enderapi.lineUp()
  enderapi.lineUp()
  term.clearLine()
  enderapi.lineUp()
  term.clearLine()
  enderapi.lineUp()
  term.clearLine()
  introPrint()
else
enderapi.lineUp()
term.clearLine()
term.write("Roll A d")
enderapi.lineDown()
term.clearLine()
print("That Wasnt A Number! Try Again.")
enderapi.lineUp()
enderapi.lineUp()
term.write("Roll A d")
end
end
end
--------------------------------------------------
--Extras--

--Pastebin: www.pastebin.com/KXRzGDcC

--CompCraft Forums:
---http://www.computercraft.info/forums2/index.php?/topic/24031-enderdice/

--Thanks All And Hope You Enjoy My Dice Roller!
--------------------------------------------------

(Little graphical bug if youre reading the above code instead of on pastebin, but it looks fine in the program)

Install:
To use this program first download by inputting this command:
pastebin get KXRzGDcC dice
And then type in "dice"

Updates:
SpoilerUpdates:
-Beta 2.0
Spoiler–Integrated my api (will auto download, to remove just delete "themccm/enderapi" or "themccm" but that will remove all my files if you have different programs of mine
–Made the color save between sessions (if you want to delete the file for some reason its located here: "themccm/enderdice/textcolor"
–Fixed some random bugs
-Beta 1.0
Spoiler–BETA IS HERE!!!!!
–Added the ability to change text color
–Added a help command
–Fixed the exit function so it will now clear the screen
–Changed default colors
–Cleaned up the code
-Alphas
Spoiler-Alpha 1.9
Spoiler–Fixed a bug where inputting more than 100000000000 (10 trillion) would crash the program
-Alpha 1.8
Spoiler–Fixed a bug where inputting anything less than one would crash the program
-Alpha 1.6/Alpha 1.7
Spoiler–Colored Text
-Alpha 1.5
Spoiler–Cleaned up code
–Added an exit function ("exit" or "e")
-Alpha 1.1-1.4
Spoiler–Made response other than what you rolled (IE: "That wasnt a number!", "You rolled a d*input* and got *output*)

Planned Features:
Spoiler-Exit function
-Choosing your own text colors

-Saving your color choice as default
-Bringing in my API


-A non-colored version for those without an advanced comp (low priority, however, because 99% of people have an advanced computer :P/>)
-A clickable GUI

Notes:
-YOU NEED AN ADVANCED COMPUTER TO RUN THIS (Due to the color, will make a non-color one soon)
-While changing color do it in only lowercase
-To exit type "exit" or "e" (capitals work)
-Its supposed to say "Roll A d", as it was created to be a DnD dice roller, it isnt a bug.
-Ideas for this, or other projects would be much appreciated, thanks. :D/>
Edited on 01 April 2017 - 07:08 AM
Waitdev_ #2
Posted 19 July 2015 - 04:05 AM
screenshots please?
Zenon #3
Posted 19 July 2015 - 04:08 AM
screenshots please?
Sure, Ill upload them now :D/>

Edit: Uploaded!
Edited on 19 July 2015 - 02:19 AM
Waitdev_ #4
Posted 19 July 2015 - 04:20 AM
i also found bugs. might wanna squash them :/
pictures/bugswhen it starts it looks like this:

and if you do a number it looks even stranger:

and when you execute that:

but just for fun, i did this:

so you gotta fix those.
ik its in early dev, but if its completely broken you probably shouldn't upload it to the forums.
and yes, i use an emulator.

EDIT: just noticed, on line 39 your looking for 'input' not 'inp' in the if statement.
Edited on 19 July 2015 - 04:06 AM
Waitdev_ #5
Posted 19 July 2015 - 04:27 AM

yet still really fun to play with xD
Zenon #6
Posted 19 July 2015 - 04:38 AM
Spoiler
i also found bugs. might wanna squash them :/
when it starts it looks like this:

and if you do a number it looks even stranger:

and when you execute that:

but just for fun, i did this:

so you gotta fix those.
ik its in early dev, but if its completely broken you probably shouldn't upload it to the forums.
and yes, i use an emulator.

EDIT: just noticed, on line 39 your looking for 'input' not 'inp' in the if statement.
I dont know what happened there, it might be because youre on an emulator? Idk, it hasnt happened to me, and seems to be working fine . . . but try redownloading just in case haha. Also, you said "and if you do a number it looks even stranger:" Are you referring to the d in "Roll A d"? If so its meant to be like that, like how it is in DnD, as this was originally meant to be used in such a place.


yet still really fun to play with xD
Thanks, glad you like it! xD
Also, thanks for the bug report and comments, though I dont know where that bug was at, I cant replicate it D:

Edit: You got one of my builds before I saw that bug and updated, try redownloading if you havent already haha
Edited on 19 July 2015 - 04:19 PM
Zenon #7
Posted 19 July 2015 - 09:50 PM
Beta Is Here! This program is starting to look like something of a final product, and as such is now a beta program.
nitrogenfingers #8
Posted 24 July 2015 - 04:25 AM
If this is aspiring to be more of a dice rolling program than just an RNG I'd recommend adding a feature to roll multiple dice; 3d6+1d8 etc.
biggest yikes #9
Posted 25 July 2015 - 04:12 PM
RIP
Spoiler
Even more RIP

RIPP
Edited on 25 July 2015 - 02:14 PM
Waitdev_ #10
Posted 03 August 2015 - 09:15 AM
i'm inspired o.O
can i make something like this?
i'd credit you in the post
Zenon #11
Posted 04 August 2015 - 02:46 AM
i'm inspired o.O
can i make something like this?
i'd credit you in the post

Yeah, if you want to directly use this thatd be fine aswell

If this is aspiring to be more of a dice rolling program than just an RNG I'd recommend adding a feature to roll multiple dice; 3d6+1d8 etc.

Thanks for the suggestion! I took about a two week break to play Dark Age Of Camelot, but Ill be coding again soon ;)/>

RIP
Spoiler
Even more RIP

RIPP

Ill try to fix this tomorrow, gonna spend some time coding this and making it a little nicer :D/>