Ticket #375 (enhancement)
Opened 1 year ago
Last modified 2 months ago
Random Module
Status: closed (worksforme)
| Reported by: | pspuser | Assigned to: | fraca7 |
|---|---|---|---|
| Priority: | major | Component: | PythonModules |
| Version: | current | Keywords: | |
| Cc: |
I tried writing a script that imported the random module to generate random numbers, but the traceback.txt reported that the module does not exist. I'd like to have one to generate proabilities for a game script I'm working on.
Attachments
Change History
09/11/07 19:35:49: Modified by pspuser
09/19/07 18:59:53: Modified by pspuser
Thanks. I hadn't put the Python folder in my root directory. Unfortunately, it still won't work when I invoke the module. Here's a portion of the code I used. Any idea where I'm going wrong?:
import random
pspuser=random.randrage(5)
def main():
scr=psp2d.Screen()
img=psp2d.Image('lemonstart.png')
fnt=psp2d.Font('font.png')
fnt.drawText(img,20,50,'LEMONADE STAND')
fnt.drawText(img,20,102,'Press START')
fnt.drawText(img,20,102,pspuser)
scr.blit(img)
scr.swap()
The full script is in the attached archive.zip file. I've commented out the bits pertaining to Stackless.
09/19/07 19:00:49: Modified by pspuser
- attachment Archive.zip added.
Example of code where random script fails
09/19/07 19:03:00: Modified by pspuser
I discovered a mistake in the code written above: When testing it, please re-write last fnt.drawText line as:
fnt.drawText(img,20,122,pspuser)
10/15/07 23:19:19: Modified by pspuser
- attachment random.rar added.
Workaround
10/15/07 23:26:53: Modified by pspuser
I've had a similar problem in pyMine, i used the following Workaround. It is an Random implementation in pure Python. soulstealer{at}gmx{dot}de
06/29/08 10:15:32: Modified by fraca7
- status changed from new to closed.
- resolution set to worksforme.
- description changed.
There are two errors in your script:
- it's random.randrange, not radrange
- You should cast 'pspuser' to str in order to pass it to drawText
Once these two points are fixed, the script works OK with the current version.

Have you copied the psp-modules in ms0:/python?