checking periods for events?

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
Craftyladynow
Newbie
Posts: 7
Joined: Thu Jul 09, 2009 8:21 pm
Projects: The University
Location: Wisconsin
Contact:

checking periods for events?

#1 Post by Craftyladynow » Wed Aug 05, 2009 4:19 pm

In my game the user will be able to pick the class they want to take and the time. Classes start on the hour and the half hour. I'm starting small 8) so my game only lasts for five days. But a class could either be on MWF or TR.

I figure that for each day I would need 48 periods. Period 1 would be at 6:30 a.m the first possible class would begin at 7am(period2). Most classes last for two or three periods. I want my game to check how many free periods the player has before class.

If they have a class at 7:30(period3) then the player may choose to grab breakfast or walk through campus during period 2.

Going to the bar would need four periods.
Eight free periods and the player could choose to work for four hours.
Sixteen free periods and the player could choose to work for eight hours.

Also if the player stays awake for 48 periods, I want them to fall asleep on the spot. And sleep for the next 20 periods through any classes they might be scheduled to take. Normally sleeping will take 16 periods.

The problem is I have no idea how to do this.

I've looked over the DSE and I think I have a handle on the events page and the script but I can't understand anything else and I didn't see anything that could check future events.

I'd welcome advice on how to do this and Thank you for taking the time to help me on this.

User avatar
tigerkidde
Regular
Posts: 155
Joined: Sun Mar 01, 2009 2:31 pm
Projects: Summer Tales of Katt and June
Contact:

Re: checking periods for events?

#2 Post by tigerkidde » Wed Aug 05, 2009 7:00 pm

As many things that I do, there is most likely a more efficient way of what I'm prescribing. But I wanted to post to let ye know I'm typing a longer post that will be pasted into this one.

edit : Provided I'm not pulled away while I'm typing it.

What I'm thinking here in terms of how to start to tackle this borders between what I "think" I know and a more crude, less beautiful way of doing it. This does not reveal the actual positioning of the code, more like pseudo code.

You have a string containing the weekday. Which could be Monday through Friday. Tuesday might be "TU" and Thursday might be "TH".

Code: Select all

$ weekday = "M"
For purposes of this example, I'm treating time periods starting from 12:00 AM as period 0.
You have an integer containing the actual period which keeps track of the time. So if it's 5:00 AM, then the actual period might be 10. If the player takes an action, it advances the actual period by the action's period cost and reduces the player's energy by the action's period cost.

i.e. It's 5:00 AM and the player wakes up with full energy.

Code: Select all

$ actual_period = 10
$ player_energy = 48
Let's say the player has the action of "Sleep In", "Eat Breakfast", and "Go to School Early". Sleeping In may cost 4 periods, BUT restore energy. Eat Breakfast may cost 1 period. Go to School Early may cost 3 periods.

Pseudocode.
After choosing the action, change the following variables.
if action == "Sleep In":
$ rest = True
$ period_cost = 4

Once the action is executed, have a function that will check to see if the player will fall asleep. First, we check to see if this is a rest action. Pseudocode.

Code: Select all

 if rest == True:
#Execute the action and calculate its benefits.
elif rest == False: #This isn't a rest action, so let's check to see if the player passes out.
    if energy - period_cost <= 0: #If say your current energy is 2 and the period cost is 3, this condition will be true
       action = "Passed Out" #And so your next real action is passing out.  Unless you want to do a hybrid action.
       #Run this function again except with the Passed Out credentials, i.e. rest = True, period_cost = 20, resets energy.
    elif energy - period_cost > 0: #There is enough energy to execute the action.
        energy -= period_cost #Deduct the period_cost from the player's energy.    
        #Execute the action, calculate its benefits
        actual_period += period_cost
        #And a function that checks a period's rollover, to be covered later.
Time goes by quicker than I realize and I've barely typed anything.
May have to address calculating the actual_period / time and checking for future events at a later time.

The future events check was going to be if the event is available on that day (perhaps five booleon values, one for each day) and an integer that contains the start time of the action. And say if we wanted to check only 8 periods in advance, a series of loops would be used to check actions available (if action_available_period >= actual_period and action_available <= actual_period + 8, then action_available_flag = True). Ideally, I'd like to throw the action into an array of available actions and display that array onto the screen to be selected. But short of that (and though inefficient still) is another loop that displays the list of possible actions on the screen based on how many actions were flagged as "true".

Will expound on this at a later time (or unless others expound or find more valid and/or effective ways).

edit: You may need a dedicated programmer to write this part of the engine.

User avatar
Craftyladynow
Newbie
Posts: 7
Joined: Thu Jul 09, 2009 8:21 pm
Projects: The University
Location: Wisconsin
Contact:

Re: checking periods for events?

#3 Post by Craftyladynow » Sat Aug 08, 2009 2:49 am

Thank you for the reply.

I think this game has become far more complicated than I originally thought. (And this was supposed to be the short easy game.) :wink:

User avatar
Mizuiru
Newbie
Posts: 11
Joined: Fri Aug 07, 2009 5:44 pm
Contact:

Re: checking periods for events?

#4 Post by Mizuiru » Sun Aug 09, 2009 12:58 am

Hi tigerkidde, just wanted to thank you for your thoughtful reply too. :) This is very relevant to the game I'm working on, and while the code itself is simple enough, I work a lot better when I see an example logic that someone's already written.

Much appreciated!

User avatar
Klawzie
Regular
Posts: 66
Joined: Thu Oct 15, 2009 9:35 pm
Organization: Kappa Creek
Tumblr: klawzie
Deviantart: klawzie
Location: SE USA
Contact:

Re: checking periods for events?

#5 Post by Klawzie » Thu Oct 15, 2009 10:36 pm

I know this thread is two months back - but this is similar to what I'd like to do. I'm very, very newbie when it comes to this - I'm mostly just playing with code I find to see if I can modify it to do what I want... Starting basically from scratch is beyond me at the moment.

I'm wanting to do something very similar to this - only to have the player choose from a list of classes at the start of the game and run the rest of the "semester" off of those choices - while also choosing two time-blocks daily. D: (I'd like them to choose their preset classes and then daily choose what to do during lunch hour and after school.)

What I'm intending will not be my first game - I intend something simpler for my first XD; - but having the ability to play with more difficult code with training wheels provided by you helpful folk enables me to do something more fun (to me) than a simple visual novel. XD; Any more insight into this sort of coding would be deeply appreciated.
Image

User avatar
JinzouTamashii
Eileen-Class Veteran
Posts: 1686
Joined: Mon Sep 21, 2009 8:03 pm
Projects: E-mail me if you wanna rock the planet
Location: USA
Contact:

Re: checking periods for events?

#6 Post by JinzouTamashii » Fri Oct 16, 2009 1:26 am

Well, the Beginner's Python Tutorials (and practice!) have done wonders for letting me "think like a programmer" but I'll bookmark this anyway...

If so many people find this useful, do you want this on the Wiki? I will be more than happy to format it and find a nice little spot for it.
Don't worry, we can get through it together. I didn't forget about you! I just got overwhelmed.
https://cherylitou.wordpress.com

User avatar
Craftyladynow
Newbie
Posts: 7
Joined: Thu Jul 09, 2009 8:21 pm
Projects: The University
Location: Wisconsin
Contact:

Re: checking periods for events?

#7 Post by Craftyladynow » Fri Oct 16, 2009 3:47 am

Yes please JinzouTamashi that would be wonderful.

Raindancing Raccoon our games sound similiar.

See I'm a freak and my favorite part of college was picking my classes. (Not going to the bar or partying or anything) I even picked classes to go to for an entire year after I left college. Now I want to make a game about it. I think the DSE would be helpful but I don't know how to make it work for what I want. So I am using a bunch of variables. I feel like I am doing a lot of work the program should be doing instead.

User avatar
JinzouTamashii
Eileen-Class Veteran
Posts: 1686
Joined: Mon Sep 21, 2009 8:03 pm
Projects: E-mail me if you wanna rock the planet
Location: USA
Contact:

Re: checking periods for events?

#8 Post by JinzouTamashii » Fri Oct 16, 2009 9:10 am

http://www.renpy.org/wiki/renpy/DSE#Conceptual_Example

Hrrm. Actually typing out the example made me realize that it wasn't very good because the structure is incomplete and it needs to be annotated/fleshed out better. I guess the demo DSE game handles that better though, right? Still, it's probably better than nothing...

If I get better at Python, I may give it a try. The tips in his post are invaluable, at any rate.
The future events check was going to be if the event is available on that day (perhaps five booleon values, one for each day) and an integer that contains the start time of the action. And say if we wanted to check only 8 periods in advance, a series of loops would be used to check actions available (if action_available_period >= actual_period and action_available <= actual_period + 8, then action_available_flag = True). Ideally, I'd like to throw the action into an array of available actions and display that array onto the screen to be selected. But short of that (and though inefficient still) is another loop that displays the list of possible actions on the screen based on how many actions were flagged as "true".
But this is too theoretical to really add any value to the wiki, so I left it off.
Don't worry, we can get through it together. I didn't forget about you! I just got overwhelmed.
https://cherylitou.wordpress.com

User avatar
Klawzie
Regular
Posts: 66
Joined: Thu Oct 15, 2009 9:35 pm
Organization: Kappa Creek
Tumblr: klawzie
Deviantart: klawzie
Location: SE USA
Contact:

Re: checking periods for events?

#9 Post by Klawzie » Sat Oct 17, 2009 4:34 am

Thanks so much for adding this to the wiki, Jinzou. :) Hopefully by the time I actually attempt this game (it'll be a monster and there is no way I'm going to work on something with that many characters as a first project) I'll understand the coding a bit better. :3 If not, I can always bump the thread again to beg... >_>

Crafty - haa! I sort of do that as well. "If I had the extra time/money - I so would take this, that or the other class..." and make out wishful schedules. I'm not sure how similar our games actually are/would be on other aspects - but if you get to this aspect of the coding and get it to work the way you want it, please let me know so I can benefit from it. XD (I'll do the same if I get to it first. ;) )
Image

User avatar
Craftyladynow
Newbie
Posts: 7
Joined: Thu Jul 09, 2009 8:21 pm
Projects: The University
Location: Wisconsin
Contact:

Re: checking periods for events?

#10 Post by Craftyladynow » Wed Oct 21, 2009 12:51 pm

I don't know how much this will help you and I'm sure there is a better way since I am using an enomorous amount of variables. I decided to have 48 periods each day and a class might span 2-5 periods. In my game some classes are on mondays but not tuesdays. So I have monday_period1 through Friday_period48

I don't know how to make the program figure out which class goes into which period so I did it myself with the help of Excel. I assigned a value to all of the school periods depending on user choices. Next I tell the program to check the first 16 periods if they are all free the user can go to work. If one of the periods is designated to 'school' it skips to the next elif statement.

Next it checks to see if 8 periods are free, if so you can work for 4 hours.

Now it checks to see if 4 periods are free, if so you have other choices.

And so on. If the first period is designated as school, then you go to class first.

Everything is now working on my game, perhaps not the way I would want it to, so now I just have to finish writing the code.

And if you think it will help when you are ready, I can show you the code for a better example.

User avatar
JinzouTamashii
Eileen-Class Veteran
Posts: 1686
Joined: Mon Sep 21, 2009 8:03 pm
Projects: E-mail me if you wanna rock the planet
Location: USA
Contact:

Re: checking periods for events?

#11 Post by JinzouTamashii » Wed Oct 21, 2009 1:45 pm

Um... I think that this might help you a little. http://docs.python.org/3.1/tutorial/controlflow.html

You can use any python statement by prefixing it with a $ in Ren'Py.

I mean, I don't use all of them, but I don't see why you can't use a range or if x > 1 or < 16, and so forth...
Don't worry, we can get through it together. I didn't forget about you! I just got overwhelmed.
https://cherylitou.wordpress.com

User avatar
JinzouTamashii
Eileen-Class Veteran
Posts: 1686
Joined: Mon Sep 21, 2009 8:03 pm
Projects: E-mail me if you wanna rock the planet
Location: USA
Contact:

Re: checking periods for events?

#12 Post by JinzouTamashii » Thu Oct 22, 2009 11:15 am

Oh, and I saw this today http://www.renpy.org/wiki/renpy/doc/coo ... ed_Endings and thought of this thread. You'll need that or something like it if you use stats, for when you're finished...
Don't worry, we can get through it together. I didn't forget about you! I just got overwhelmed.
https://cherylitou.wordpress.com

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Ocelot, zyric