Page 1 of 1

help with screen to displays random messages

Posted: Tue Feb 28, 2017 7:23 pm
by jadeon12
Hello Fellow Renpy users,

I am working on this game where I have a screen that opens to display certain random messages, its a Krystal ball whom the player can take it out of its pocket peer in it and get a random message.

Here is part of the code:

Code: Select all


label ballgaze:

$ ball = renpy.random.randint(1, 4)
if ball == 1:
    $messa = "Today its going to Rain heavily., but stay focused on your purpose" 
if ball == 2:
    $messa = "What does not kill you will make you stronger." 
if ball == 3:
    $messa = "Your destiny is in your hands." 
if ball == 4:
    $messa = "Remember the reason you are here!!"



screen kriball_button:
    imagebutton:
            idle "appear_idle.png"
            hover "appear_hover.png"
            action  [Show ("kriball_screen "), Hide("kriball_button")] align (.40,.90)

screen kriball: 
    modal True 
    window:
        vbox:   
            label "Krystal Ball"           
            text " Digging in your pocket you take out the Krystal ball and peer inside for a message:"
            text ""
            text " [messa] "

This code works and displays a random message when the screen is opened, however if i close and reopen the screen it will keep giving me the same message instead of giving a random one.

How can i make it that the screen will display another random message after i close and reopen it again?

I understand that somehow the message ballgaze "function" should run each time the screen is opened in order to generate a new one.

But I cannot figure out how to get it done, I hope someone can give me a hand with this.

Re: help with screen to displays random messages

Posted: Tue Feb 28, 2017 8:45 pm
by papiersam
You could use a python function instead. Possibly something like this:

Code: Select all

init python:
    
    import random #need the module
    
    def ballgaze(): #the function
        ball = random.randint(1, 4)
        if ball == 1:
            return "Today its going to Rain heavily., but stay focused on your purpose" 
        if ball == 2:
            return "What does not kill you will make you stronger." 
        if ball == 3:
            return "Your destiny is in your hands." 
        if ball == 4:
            return "Remember the reason you are here!!"
            
label start:
    
    "Test"
    
    $messa = ballgaze()
    
    "[messa]"
    
    "Now we can call the screen:"
    
    call screen kriball_button


screen kriball_button:
    imagebutton:
            idle "appear_idle.png"
            hover "appear_hover.png"
            action  [Show ("kriball_screen "), Hide("kriball_button")] align (.40,.90)

screen kriball_screen: 
    modal True 
    window:
        vbox:   
            label "Krystal Ball"           
            text " Digging in your pocket you take out the Krystal ball and peer inside for a message:"
            text ""
            text ballgaze() #call the function

Re: help with screen to displays random messages

Posted: Tue Feb 28, 2017 9:27 pm
by jadeon12
r_sami wrote:You could use a python function instead. Possibly something like this:

Code: Select all

init python:
    
    import random #need the module
    
    def ballgaze(): #the function
        ball = random.randint(1, 4)
        if ball == 1:
            return "Today its going to Rain heavily., but stay focused on your purpose" 
        if ball == 2:
            return "What does not kill you will make you stronger." 
        if ball == 3:
            return "Your destiny is in your hands." 
        if ball == 4:
            return "Remember the reason you are here!!"
            
label start:
    
    "Test"
    
    $messa = ballgaze()
    
    "[messa]"
    
    "Now we can call the screen:"
    
    call screen kriball_button


screen kriball_button:
    imagebutton:
            idle "appear_idle.png"
            hover "appear_hover.png"
            action  [Show ("kriball_screen "), Hide("kriball_button")] align (.40,.90)

screen kriball_screen: 
    modal True 
    window:
        vbox:   
            label "Krystal Ball"           
            text " Digging in your pocket you take out the Krystal ball and peer inside for a message:"
            text ""
            text ballgaze() #call the function
Hello r_sami,

Thank you for your reply, i tried the above function, although the screen opens, the message still does not update(does not change) after one closes and opens the screen by pressing the imagebutton.

it gives me the same message,

I used both call dcreen or show screen but its not working

Re: help with screen to displays random messages

Posted: Tue Feb 28, 2017 9:31 pm
by gas
(import random??)

Another practical solution...

Code: Select all

default tenses=["You're having a bad day","I think someone will help you in a forum","Someone will write a code for you"]

label start:
     show screen kriball_button
     "Did you like horoscopes?"

screen kriball_button:
    imagebutton:
            idle "appear_idle.png"
            hover "appear_hover.png"
            action  [Show ("kriball_screen"), Hide("kriball_button")] align (.40,.90)

screen kriball:
    modal True
    $ myfate=renpy.random.choice(tenses) #pick a random tense from the list "tenses"
    window:
        vbox:   
            label "Krystal Ball"           
            text " Digging in your pocket you take out the Krystal ball and peer inside for a message:"
            text ""
            text " [myfate] "

so you can just add new tenses and everything's fine.
(Anyway you need a button to hide the kriball screen, somehow. Don't forget to add it!)

Re: help with screen to displays random messages

Posted: Tue Feb 28, 2017 10:11 pm
by papiersam
(import random??)
Ah, my bad. Should look like this, then:

Code: Select all

    from random import randint
    
    def ballgaze():
        ball = randint(1, 4)
        if ball == 1:
            return "Today its going to Rain heavily., but stay focused on your purpose" 
        if ball == 2:
            return "What does not kill you will make you stronger." 
        if ball == 3:
            return "Your destiny is in your hands." 
        if ball == 4:
            return "Remember the reason you are here!!"

Re: help with screen to displays random messages

Posted: Wed Mar 01, 2017 1:08 am
by Divona
r_sami wrote:
(import random??)
Ah, my bad. Should look like this, then:
Could just use "renpy.random" instead of import, no?

Code: Select all

    def ballgaze():
        ball = renpy.random.randint(1, 4)
        if ball == 1:
            return "Today its going to Rain heavily., but stay focused on your purpose" 
        if ball == 2:
            return "What does not kill you will make you stronger." 
        if ball == 3:
            return "Your destiny is in your hands." 
        if ball == 4:
            return "Remember the reason you are here!!"

Re: help with screen to displays random messages

Posted: Wed Mar 01, 2017 6:17 am
by jadeon12
Thank you very much all of you,

The correction of R_sami is working, and Gas method also, need to try Givona's yet.

However I tried to make a similar function without random for another feature of the glass ball, where i want it to change color and size according to certain events like what the player ate or what his mood are as he opens the screen:

I have the variable mood that is set to 1 for green.
If the player eats a chili it should change to red, and the screen will have [messa] substituted for that value, however its not working, when i open and close the screen, the value does not change accordingly it stays at green.


I hope you can give me a hand friends.

Code: Select all

 

init python:
     
    def ballgaze():
        global mood
        if mood == 1:
            return "green"
        if mood == 2:
            return "blue"
        if mood == 3:
            return "red"
        if mood == 4:
            return "yellow"
           
label start:
   
    "Test"
    $ mood = 1
    $messa = ballgaze()
   
    "[messa]"
   
   
    show screen kriball_button

label colortest:
menu:
      "eat a chili":
          $mood = 3
          "you ate a fiery chili"
          jump colortest
      "eat a mango":
          $mood = 4
          "you ate a sweet mango"
          jump colortest
      "eat blueberries":
          $mood = 2
          "you ate a cooling berrie"
          jump colortest
          


screen kriball_button:
    imagebutton:
            idle "appear_idle.png"
            hover "appear_hover.png"
            action  [Show ("kriball_screen "), Hide("kriball_button")] align (.40,.90)

screen kriball_screen:
    modal True
    window:
        vbox:   
            label "Krystal Ball"           
            text " Digging in your pocket you take out the Krystal ball and peer inside for a message:"
            text ""
            text "the ball is giving a [messa]ish pulsing glow"
            
    imagebutton:
            idle "closeappi_idle.png"
            hover "closeappi_hover.png"
            action [ Hide("kriball_screen"), Show("kriball_button")] align (.40,.90) 

Re: help with screen to displays random messages

Posted: Wed Mar 01, 2017 5:13 pm
by gas
Ok let's simplify everything.
You want for the sphere to say something based on the mood value.

If you set mood=1 in a label, renpy put at 1 each time he reach again that label.
So, define it at first OUTSIDE the normal course of events.
Then use a list to link the various conditions to the variable. Is called INDEXING.
in python, each element of a list can be retrieved by referring his index number, counting FROM 0 ONWARD.

Code: Select all

default mood=0
default shade=["green","red","blue"]  # so, mood 0 = green, mood 1= red, mood 2= blue
label start:
    show screen kriball
label feast:
    menu:
        "Eat mango!":
            $ mood=0
            "You ate a juicy mango!"
        "Eat chili!":
            $ mood=1
            "You ate a fiery chili pepper!"
        "Eat alien food":
            $ mood=2
            "Something strange happened..."
    jump feast
screen kriball_button:
    imagebutton:
            idle "appear_idle.png"
            hover "appear_hover.png"
            action  [Show ("kriball_screen "), Hide("kriball_button")] align (.40,.90)

screen kriball_screen:
    modal True
    $ yourcolor=shade[mood]
    window:
        vbox:   
            label "Krystal Ball"           
            text " Digging in your pocket you take out the Krystal ball and peer inside for a message:"
            text ""
            text "the ball is giving a [yourcolor]ish pulsing glow"

With this logic it's very easy to accomplish what you want for.
Change the mood (the index) and retrieve the string.

If you find some other difficulty, ask for! That kriball seems fun!

Re: help with screen to displays random messages

Posted: Thu Mar 02, 2017 2:46 am
by jadeon12
gas wrote:Ok let's simplify everything.
You want for the sphere to say something based on the mood value.

If you set mood=1 in a label, renpy put at 1 each time he reach again that label.
So, define it at first OUTSIDE the normal course of events.
Then use a list to link the various conditions to the variable. Is called INDEXING.
in python, each element of a list can be retrieved by referring his index number, counting FROM 0 ONWARD.

Code: Select all

default mood=0
default shade=["green","red","blue"]  # so, mood 0 = green, mood 1= red, mood 2= blue
label start:
    show screen kriball
label feast:
    menu:
        "Eat mango!":
            $ mood=0
            "You ate a juicy mango!"
        "Eat chili!":
            $ mood=1
            "You ate a fiery chili pepper!"
        "Eat alien food":
            $ mood=2
            "Something strange happened..."
    jump feast
screen kriball_button:
    imagebutton:
            idle "appear_idle.png"
            hover "appear_hover.png"
            action  [Show ("kriball_screen "), Hide("kriball_button")] align (.40,.90)

screen kriball_screen:
    modal True
    $ yourcolor=shade[mood]
    window:
        vbox:   
            label "Krystal Ball"           
            text " Digging in your pocket you take out the Krystal ball and peer inside for a message:"
            text ""
            text "the ball is giving a [yourcolor]ish pulsing glow"

With this logic it's very easy to accomplish what you want for.
Change the mood (the index) and retrieve the string.

If you find some other difficulty, ask for! That kriball seems fun!
Yes, I understood the coding, it and its working!

Thank you very much Gas!