Sandbox in RenPy?

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
HoAbGa
Newbie
Posts: 12
Joined: Mon Oct 30, 2017 4:38 am
Contact:

Sandbox in RenPy?

#1 Post by HoAbGa »

Hey Guys,

I hope i hit the right forum here :?:

Story short: I need help with the implementation of a special feature.

Explanation:
I'm about to create a game that will work like a little sandbox. With the imagemap-function, I have created a map with different locations, as well as scenes in which one can "move".

Now comes the tricky part.
How does the game know which event is playable?

My Plan:
At game start you have 4 positions on the map. All are visitable. Nothing happens in 3 places, or you can possibly make small talk with another character. Only at location 4, a story scene will be started.
After this scene you have one more position on the map.
The main story continues in another place that you first have to find.

How can I teach renpy to remember the sequence of events while using the flexible and growing map?

Has anyone ever done such a thing?

Thank you for your attention and help in advance.

Best,
HoAbGa

User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: Sandbox in RenPy?

#2 Post by ISAWHIM »

Here is a basic little "game"... Just to give you some ideas.

Code: Select all

#put this in "scripts.rpy"
# The game starts here.
screen myLocations:
    #See documentation for "screen actions". https://www.renpy.org/doc/html/screen_actions.html
    #imagebuttons require at-least two images... "area01_idle.jpg" and "area01_hover.jpg"
    imagebutton auto "area01_%s.jpg" xpos 200 ypos 200 action [SetVariable("myLocation", 1), Jump("area01")]
    imagebutton auto "area02_%s.jpg" xpos 200 ypos 400 action [SetVariable("myLocation", 2), Jump("area02")]    

#Initial starting values
define myLocation = 0
define mission = "feed"
define feed = 0
define clean = 0
define food = 4

label start:

label waitForInput:
    $ myLocation = 0
    show screen myLocations
    scene home
    "You are at home, location #[myLocation]. Select something to do."
    #some idle stuff here, so it never actually advances... animation loops, time passage, etc...

    #Returns to the beginning, if they do advance the screen by clicking or hitting a button on the keyboard
    jump waitForInput

label area01:
    scene zoo
    "You are at the zoo, location #[myLocation]."
    if mission == "feed":
        "You came to feed the lions... Great!"
        $ feed += 1
        $ food -= 1
        "You have fed the lions [feed] times. You have [food] servings left."
        if food == 0:
            $ mission = "clean"
    elif mission == "clean":
        "You came to clean the lions cages... Great!"
        $ clean += 1
        "You have cleaned [clean] lion cages."
        $ mission = "shop"
    else:
        "You have no food to feed the lions. Visit the store."
    jump waitForInput

label area02:
    scene store
    "You are at the store, location #[myLocation]."
    if mission == "shop":
        "You came to buy lion food."
        $ food = 4
        "You purchased [food] servings of food."
        $ mission = "feed"
    elif mission == "clean":
        "I think you should clean the lion cages, before you buy more food."
    else:
        "You still have [food] servings of food. Go feed the lions"
    jump waitForInput
This is just a rough set of code... I would not have used this, like it is... but it functions for the example.

Needs 7 images...
home.jpg <-- background 1080p
store.jpg <-- background 1080p
zoo.jpg <-- background 1080p
area01_idle.jpg <-- The zoo button 100x200
area01_hover.jpg <-- The zoo button 100x200 (Change to indicate "Go to the zoo" on mouse-over)
area02_idle.jpg <-- The store button 100x200
area02_hover.jpg <-- The store button 100x200 (Change to indicate "Go to the store" on mouse-over)
Last edited by ISAWHIM on Mon Oct 30, 2017 8:41 am, edited 4 times in total.

User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: Sandbox in RenPy?

#3 Post by ISAWHIM »

Essentially, with each mission you create...

Code: Select all

label myMissionName:
You need to do "something", in order to get there.

It could be some "Value" which is checked...
(if x = 42) then go to this new mission...

It could be a simple chain of events...
label myMission01:
#do this, then show some new button for myMission02.

It could be more complex, using "Choices" or by completing multiple things...
(if x = 42 and today="sunday" and home is not "painted blue") then go to this mission...
or... Show new screen with ten new buttons on them.

Ultimately, staying within a "game loop"... Where you structure the interactions that lead you away, which ultimately return again... Until the end...

You can also make a "list" of missions that are available. So... You can have "feeding" and "cleaning" and "buying" available, all at once. You just have to check to see if an item {mission} is in the list.

HoAbGa
Newbie
Posts: 12
Joined: Mon Oct 30, 2017 4:38 am
Contact:

Re: Sandbox in RenPy?

#4 Post by HoAbGa »

Hey ISAWHIM,

Thank you so much for the inspiration. I will try that ;)

Thank you and have a wonderfull week.

User avatar
磯七ラスミ
Regular
Posts: 65
Joined: Tue Nov 29, 2016 4:31 pm
Projects: If Facts Aren't Alibi | 盲点に日光 (Mōten ni Nikkō) | Nest, Treetop | Untail Wire Stretch
Contact:

Re: Sandbox in RenPy?

#5 Post by 磯七ラスミ »

Wow, I'm trying to make something like that.

Is better if you use python functions and classes to build your inner engine (I'm not sure if Ren'Py has its own code for that). I was doing something like what ISAWHIM said for now, because I think is very hard to learn all python language syntax before the little fantasy take shape.
The thing I'm talking helps to make easier to edit your code. Functions and classes are a powerful way to maintain your code clean and tidy. You'll be copying and pasting code too often otherwise.

I recommend splitting your code into different .rpy files, like drawers in a dresser for saving time and sanity.

Then for the map, you may use something called imagemaps, overlaying a hover image to your graphic map, in order to have the state of buttons when player puts the cursor over your buttons/selectable zones.
Sorry if I'm not a source linker kind of person. It makes me feel shy too look for that stuff, and I start to sweat. I'd make for an interesting VN character. :o

Anyways, I hope my information be of help.

By the way, I hope there was a forum for code. I always go for Creator Discussion when I'm not sure about on which one to post.

EDIT:
Oh, right! My bad. Just when I talked about being afraid to make mistakes. I forgot we was talking about Ren'Py, so the correct forum is Ren'Py Questions and Announcements.
My wonder is with a forum for creators to discuss coding practices.
Last edited by 磯七ラスミ on Tue Oct 31, 2017 7:12 am, edited 1 time in total.

User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: Sandbox in RenPy?

#6 Post by korova »

By the way, I hope there was a forum for code. I always go for Creator Discussion when I'm not sure about on which one to post.
What don't you use the "Ren'Py Questions and Announcements" forum ? This is where people ask questions regarding ren'py coding...

HoAbGa
Newbie
Posts: 12
Joined: Mon Oct 30, 2017 4:38 am
Contact:

Re: Sandbox in RenPy?

#7 Post by HoAbGa »

Hi all and thank you so much for the help in that case.

Current status:
I have successfully created a map and made the various locations visitable with the imagemap system. Exactly I imagined it!

This is a small example how i have realized it:

Code: Select all

screen mainmap: #here i prepare my imagemap / worldmap with all visitable places
    imagemap:
        ground "mapidle.png"
        hover "mapover.png"
        
        hotspot (1285, 76, 48, 73) clicked Jump("home")
        
# The game starts here.
label start:
    "Everything that belongs to the start of the game comes in here. The first scene of a newly loaded game starts in your own home."
    jump mainmap

label mainmap:
    call screen mainmap #Displaying the imagemap

label home:
    "It is your home BOAY!"
    jump mainmap

Next on my to-do list:
Find out how the if-funktion will work to remember what scene (mission / sidemission) you have played, and which not and which mission is available at the moment and which not.

Best,
HoAbGa

HoAbGa
Newbie
Posts: 12
Joined: Mon Oct 30, 2017 4:38 am
Contact:

Re: Sandbox in RenPy?

#8 Post by HoAbGa »

And before I forget it:
Of course, the player can make decisions in different places and his decisions influence the game.
These variables must also be considered.

If you have useful tips, I'm grateful.
Thank you in advance :!:

HoAbGa
Newbie
Posts: 12
Joined: Mon Oct 30, 2017 4:38 am
Contact:

Re: Sandbox in RenPy?

#9 Post by HoAbGa »

I had the idea to solve it via a point system. Do you think that works?

Every place is a scene. Every time a scene is entered, the score will be scanned.
Depending on the score, the mission will be executed (Jump -> missionscene).

When you finish a mission, you get a new score, which then "opens" more options in the worldmap.

It will be difficult to keep this score correct, but it should work.
Or am I making a mistake?

Thank you,
HoAbGa

User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: Sandbox in RenPy?

#10 Post by ISAWHIM »

Yes, that works well, for each area.

You will use a lot of "if" comparisons, but that is to be expected.

This is not actual code... Something like this would be in each area. Use multiple conditions checking where needed.

Code: Select all

if jessStats.talk == 1 or jessStats.mood == "mad":
    jess "I have nothing to say to you today."
    if jessStats.hasCookie == True:
        $jessStats.talk = 2
elif jessStats.talk == 2:
    jess "Glad you stopped bye. I have so much to tell you."
    $jessStats.talk = 3
elif jessStats.talk == 3:
    jess "I told you all I know. Want a cookie?"
    if jessStats.hasCookie == True:
        jess "Here you go..."
        $jessStats.hasCookie == False
    else:
        jess "Sorry, I forgot. I don't have any cookies!"
        #Disable this area, since there is nothing to do here anymore.
        $area04.enabled = False
else:
    jess "Who are you?"
    $jessStats.talk = 1
First she has no clue who you are.
Second, she has nothing to say... She is waiting for a cookie to give to you, to be "set" somewhere. "OR" if she is mad, she will not talk to you.
(repeat until she gets a cookie to give)
Now, she will reply with the last bit of info. (But you don't get the cookie yet...)
Visiting again, she offers a cookie, and has one to spare. (Now you get it. Given to her from some other task you did before-hand. Just as a limiting variable.)
Visiting one last time, she offers a cookie, but has none... Now the game locks-out this area, or her... Since there is absolutely nothing to do here now. Talking to her that last time could also be a trigger for opening another area... passing someone-else another "cookie" so to speak.

All that is totally inert to anything-else going on, and can be done at any time. Thus, the "free-roaming" aspect is kept. But the "cookie" makes it interactive with other areas, for progression/advancement.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]