generating randomly created word issues!

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
lovebby
Regular
Posts: 106
Joined: Mon Sep 09, 2013 12:24 am
Deviantart: lovebby
Contact:

generating randomly created word issues!

#1 Post by lovebby »

So this code has suddenly acted up,

Code: Select all

    $ num = renpy.random.randint(1, 5)  
    if num == 1:
        $w1 = vow, con1, con2, con3
    if num >= 3:
        $w1 = con1, vow, con2, con3
    if num >=5:
        $w1 = con1, con2, vow, con3
What I'm trying to do is make the game create a random short word, and when I last check it it gave out

Code: Select all

'u', 'l', 't', 's'
which I just wanted it to be ' ults ' but was readable. I checked it today and it gave me

Code: Select all

u'u', u'l', u't', u's'
which makes it so much more difficult to look at! Any help on this, just to get to spell out a simple word?

The rest of the code looks like

Code: Select all

 $ con3 = renpy.random.choice (['j', 'b', 'd', 'k', 'f', 'g', 'h', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'])
        $vow = renpy.random.choice (['a', 'e', 'i', 'o', 'u',])
        $ num = renpy.random.randint(0, 20)  
(the con 1 & 2 are the same as con3, and its indented correctly.)

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: generating randomly created word issues!

#2 Post by philat »

I don't know what you want to do with this random word, I guess, but you can use .join() to get the word without spaces.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: generating randomly created word issues!

#3 Post by Imperf3kt »

You should probably change your order a little. I suggest the following:

Code: Select all

    $ num = renpy.random.randint(1, 5)  
    if num == 5:
        $w1 = con1, con2, vow, con3
    elif num >= 3:
        $w1 = con1, vow, con2, con3
    else:
        $w1 = vow, con1, con2, con3
But looking at this, what happens if Randint returns 2? In my example it'll treat it as if it was "1"
Your code also has no space if num >=5:
- it should be if num >= 5:

You also have

Code: Select all

$vow = renpy.random.choice (['a', 'e', 'i', 'o', 'u',])
I don't think this matters, but $vow has no space between $ and vow like the rest of your code.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
lovebby
Regular
Posts: 106
Joined: Mon Sep 09, 2013 12:24 am
Deviantart: lovebby
Contact:

Re: generating randomly created word issues!

#4 Post by lovebby »

@philat
How would I use .join()? I'm guessing throwing the con and vow in there with commas separating them? Sorry I'm pretty bad with python stuff!

@imperf3kt
Ah yes, I always forget about using the higher value first, haha. Thanks! And the spaces never seemed to matter or bring up an error on those instances? I've used them in plenty previous codes, it's kinda sloppy sure but I've never had a problem with it.

and the u"" issue I'm having is still there and I'm not sure what's causing it? I'm guessing with an update?

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: generating randomly created word issues!

#5 Post by philat »

Well, I mean. GTFY...? https://www.tutorialspoint.com/python/string_join.htm

The basic syntax in your case would be something like "".join(w1).

Post Reply

Who is online

Users browsing this forum: No registered users