Random image tag for character attire

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
Steffenator
Regular
Posts: 53
Joined: Fri Feb 17, 2017 11:58 am
Contact:

Random image tag for character attire

#1 Post by Steffenator »

Ok, I'm trying to throw together a random generator so that when a certain character enters the scene, their clothing is selected at random, and then that value is used through the rest of the scene, until next time we bump into that person.

here's what I tried...

Code: Select all

####            Variables           ####

$ lClothes = renpy.random.randint(0, 1)

### Image tags are as follows.
###  1st tag = character,
###  2nd tag = mood,
###  3rd tag = clothing option (0 = casual, 4 = formal),
###  4th tag = pose variation.


label start:
    $ lAttire = 0

    if lClothes = 0:
        $ lAttire = 0
    else:
        $ lAttire = 4

    show laura laugh 0 1 at left with dissolve
    l "Hello."
    show laura smile [lAttire] 1 at left with dissolve
    l "This one."
    show laura smirk [lAttire] 1 at left with dissolve
    l "That one."
    show laura think [lAttire] 1 at left with dissolve
    l "Maybe this one here."
    show laura shrug [lAttire] 1 at left with dissolve
    l "The end."
I could have used the randfloat thingy, but I plan on having more than two options down the road.

The above code is entirely for test purposes, so it's a bit nonsensical.

With the code as it is, the 'if' statement looks like it satisfies the engine, though that's not to say that it works as intended. It won't let me into the game yet. The only errors I'm getting now are an "end of line expected" for each 'show' statement.
I'm guessing it didn't like the [lAttire] thing.

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 33: end of line expected.
    show laura smile [lAttire] 1 at left with dissolve
                               ^

File "game/script.rpy", line 35: end of line expected.
    show laura smirk [lAttire] 1 at left with dissolve
                               ^

File "game/script.rpy", line 37: end of line expected.
    show laura think [lAttire] 1 at left with dissolve
                               ^

File "game/script.rpy", line 39: end of line expected.
    show laura shrug [lAttire] 1 at left with dissolve
                               ^

Ren'Py Version: Ren'Py 6.99.12.3.2123
There once was a language called Ren'Py
that made all the wannabes cry... with joy.
It gave them the power,
they spent every hour,
to finish a game, or die.


User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Random image tag for character attire

#2 Post by gas »

Had you tried to remove those square brackets?
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
Steffenator
Regular
Posts: 53
Joined: Fri Feb 17, 2017 11:58 am
Contact:

Re: Random image tag for character attire

#3 Post by Steffenator »

Ok, now it's telling me that my syntax on the 'if' line is wrong.
I tried taking out the $'s, but it didn't like that either.

So, scratch the part about the if statement being good... It's aparently fubar'd too. :p
There once was a language called Ren'Py
that made all the wannabes cry... with joy.
It gave them the power,
they spent every hour,
to finish a game, or die.


User avatar
Steffenator
Regular
Posts: 53
Joined: Fri Feb 17, 2017 11:58 am
Contact:

Re: Random image tag for character attire

#4 Post by Steffenator »

Ok, update...
As usual, I forgot something minor. My 'if' statement was missing the second equal sign. So, that part's good now.

'Nother thing. The image tags don't like to be numbers... AND... it only wants three tags total (Bogus).
After I swapped the numbers for letters, deleted the fourth tag, replaced the randomizer to the renpy.random.choice one (because I didn't know if randint would do letters,) AND put the square brackets back around the lAttire tag, it successfully randomizes my third tag, but for some reason, it doesn't actually display my image, but rather that blank anime piggytail girl one. I know it's randomizing successfully because of how it displays the image name on the anime girl silhouette.

I wonder if this has something to do with how the image listings are specific, but the image that's being called upon uses a variable.
There once was a language called Ren'Py
that made all the wannabes cry... with joy.
It gave them the power,
they spent every hour,
to finish a game, or die.


User avatar
Steffenator
Regular
Posts: 53
Joined: Fri Feb 17, 2017 11:58 am
Contact:

Re: Random image tag for character attire

#5 Post by Steffenator »

'Nother update!!!

I figured it out. After a massive hint from a certain forum member, who shall remain nameless so's that he or she doesn't get bombarded with PMs from other noobs like me, I devised a simple solution.

Having been steered away from image tags, I read up on ConditionSwith(), stuffed one full of booleans, and came up with this.

Code: Select all

image ehappy1 = ConditionSwitch("eAttire <= 3", "Casual01.png", "eAttire > 3 and eAttire <= 7", "Formal01.png", "eAttire > 7 and eAttire <= 11", "Grubby01.png")
Then at the beginning of any scene to which I want that applied, I just add this...

Code: Select all

$ eAttire = renpy.random.randint(0, 11)
Don't ask me why I used 0-11 instead of just 1-12. I'm just weird like that, and it gives me the freedom to add a few more options down the road without having to rewrite too much.
Anyway, this totally worked on the first attempt. It's not attractive, but it did the job in two lines of code.
I knew there had to be a simple way.
There once was a language called Ren'Py
that made all the wannabes cry... with joy.
It gave them the power,
they spent every hour,
to finish a game, or die.


Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]