2022-01-22 15:27:12 (edited by PatrykK 2022-01-22 21:29:11)

Hi.
who wants a simple dice script?
it simulates a 6 sided dice, I wanted to make a dice roller, but because there's no good compiller for python, I will just share it as a module, if someone is interested.
it uses a random module and simplifies it for one task.
here is link
https://patrykproductions.tk/wp-content … dicelib.py
just type dicelib.dice()
and it just works.

meow meow.

2022-01-22 20:20:01

@1, you could have uploaded it, the topic title make's the readers think that: 1: you have something to ask about it, or 2:, you have uploaded it, about compilers, you can take python, and change the way that the bite code's are written to make it harder to decompile, but python is not A compiled programming language

"But did you, in your three-piece psychology and 1950's technobrain,
ever take a look behind the eyes of the hacker?  Did you ever wonder what
made him tick, what forces shaped him, what may have molded him?"

2022-01-22 21:23:29

I will upload it.
I actually made a dice program using my dice lib, I will upload dice lib.

meow meow.

2022-01-22 21:29:30

done, and docs and link are in 1th post

meow meow.

2022-01-23 02:43:17 (edited by stewie 2022-01-23 02:45:15)

Were you trying to have the dice function itself roll the die? If so it isn't doing that, it'll currently just perform the roll when the module is imported. Also you should do randint(1, 6) instead of randint(0, 6) since a die doesn't have a 0 side. You may want to try something like this

import random

def dice():
    roll = random.randint(1, 6)
    return roll

# Only perform a rol if this script is called directly. If it is imported the dice function can be called instead to return a roll.
if __name__ == "main":
    result = dice()
    print("roll is " + result)
Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.

2022-01-23 19:25:48

about the 0,6 thingy, yeah, it will be fixed soon, I know about it.
the module will not roll the dice itself, because I made it as a module, xd.

meow meow.

2022-01-23 20:00:46 (edited by ashleygrobler04 2022-01-23 20:28:43)

Here's a dice class I wrote last year, I wanted to use it in a game...

 import random
import random

class dice:
    def __init__(self):
        self.maxval=6
    def roll(self):
        value=random.randint(1,self.maxval)
        return value


 

Usage:

 test=dice.dice()

test.roll() 
best regards
never give up on what ever you are doing.

2022-01-23 20:05:25

@7 why is it a class if it has a single method that doesn't care about the class? why not just make it a function?
and why is the roll() function inside __init__?

2022-01-23 20:27:42 (edited by ashleygrobler04 2022-01-23 20:29:24)

@8 sorry, modified the class a little. That's why there's errors. I'll update my previous post. Thanx for noticing, I was in a hurry while writing the code.
Edit: Modified the previous post to make sence.

best regards
never give up on what ever you are doing.

2022-01-23 20:42:10

I'm going to update my lib but there are issues with my hoster.

meow meow.

2022-01-23 22:25:33

2.0 changelog
*removes the 0 side
*the lib nolonger prints the result, it now outputs it to a variable called roll
I will upload it when I contact my hoster about issue

meow meow.

2022-01-23 23:00:53

@1, look up compiling python code on google and you'll get helped out. I'd explain in some more detail but I don't enjoy writing on this keyboard. Pyinstaller is common so is luitca

You ain't done nothin' if you ain't been cancelled
_____
I'm working on a playthrough series of the space 4X game Aurora4x. Find it here

2022-02-03 20:38:41

As we all know, my coding methods are stupid, but maybe you can try this. I'm probably going to receive a lot of criticism for this but...

from random import randint
def roll(min=1,max=6):
    return randint(min,max)

#If you wanted to roll multiple.
def roll_multiple(amount,min=1,max=6):
    #Th will return a list of ints.
    vals = []
    for i in range(0,1mount):
        vals.append(randint(min,max))
    return vals
-----
YouTube
GitHub
Discord: @tunmi13#1880