Ren'Py Character Locator

Zenathos815

Newbie
Jul 26, 2017
53
23
Hey Guys!

I'm back to bug you again because you are so much more helpful and I don't feel the need to be cloak and dagger about my intentions when trying to get something figured out.

An update on my game if you are interested;
You don't have permission to view the spoiler content. Log in or register now.

The main reason I am here right now is actually a weirder one I can't seem to find any good examples of. I wanted to get a "character tracker" thrown together to make my life easier. Now that I am writing this I feel like there is a few examples out there but not any I can think of. Basically I want to create a way to track who is where and when. I have the time thing all figured out and a whole list of locations, but I wanted a way to track what character is where at what time.

The best example is when I write a scene, in this case the character accessing his computer, where the options are dependent on who is available to the mc I wanted a way for the game to know who should be available when or where they are. When I was writing the idea I made a static schedule that each character follows each week, I may switch it up a bit so that its not identical each week but basically in this case with the computer, I want the game to know if a character is online so I am not writing a boatload of if statements for each and every scene. I have 7 characters that are all available at different times in different locations.

In this first demo I am using the character "C" and you can only manipulate certain stats when she is at her computer. I would like if the game knew where she was because on Monday in the morning she might be at her desk where the mc has access to her but Tuesday morning she might be running errands. So I want to be able to create something that is aware of what she is up to so instead of a plethora of if statements for every single day on every single label I can simply say "is C is present at x location? if show option a, if no then make option a unavailable" This way If she is at her pc in the morning the option is available ther and if not I want the mc to more or less have the option to get up go to another location and if she is present there the appropriate option is given.

I am not asking someone to provide me a code that will do this (though I won't object) but more of a way to approach building this out. I have 7 planned characters and would like a way to plug in where they are and when so that I am not doing huge arrays of if statements for each label pertaining to each time of day at each location for each character for obvious reasons. Any suggestions would be totally awesome and will help get this out sooner so I can give you guys something. As always much appreciated and sorry for my winded-ness.
 

Belle

Developer of Long Live the Princess
Game Developer
Sep 25, 2017
3,092
10,281
It sounds to me like you want a basic set of methods/functions, which is always a good idea regardless. In Ren'py that will often just be a label with a return statement at the end. You call this label then check its return value after it's done. This way you can place all your logic inside that single label. The label can check anything you can think of, and the only thing you need to do later is to call it.

I do a similar thing in my own game. Certain characters may be in specific locations at various times of the day/week. Every time I update the time of day I run through a label (like described above) and set a variable that quickly tells me if that character is available in a specific location. That way I only have to write the character's "AI" once, but can refer to the results as often as I like.

The basic thing to keep in mind is this: Don't rewrite code. Use every opportunity to centralize code you use often in a separate label. This not only makes your code easier to read, but it also reduces the risk of bugs considerably.
 

Zenathos815

Newbie
Jul 26, 2017
53
23
It sounds to me like you want a basic set of methods/functions, which is always a good idea regardless. In Ren'py that will often just be a label with a return statement at the end. You call this label then check its return value after it's done. This way you can place all your logic inside that single label. The label can check anything you can think of, and the only thing you need to do later is to call it.

I do a similar thing in my own game. Certain characters may be in specific locations at various times of the day/week. Every time I update the time of day I run through a label (like described above) and set a variable that quickly tells me if that character is available in a specific location. That way I only have to write the character's "AI" once, but can refer to the results as often as I like.

The basic thing to keep in mind is this: Don't rewrite code. Use every opportunity to centralize code you use often in a separate label. This not only makes your code easier to read, but it also reduces the risk of bugs considerably.
Interesting... So meaning you program a set of labels that act as the AI? I can do that, I managed to use that to set up my timeskip which is still buggy in certain menus but I blame my shitty use of those while trying to factor the character things so I would still blame that. Do you have an example of how that would work for say multiple char? I just want an idea of how to structure it
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,145
14,829
For to achieve what you want, try to break down it in small parts.
So, you need what :
  • A weekly schedule for each one of your characters ;
  • A way to modify/generate this schedule depending of the change made in the game ;
  • A way to know what the schedule say for now ;
  • A way to interrogate the schedule for all the characters ;
  • A way to jump/call to a label you don't know when you write your code.
There's clearly three main parts: Schedule, interrogation, jump/call.
But in fact you just have two parts. Both the interrogation and jump/call have the same answer.

You don't have permission to view the spoiler content. Log in or register now.


You don't have permission to view the spoiler content. Log in or register now.

Note:
The code is "as is". I wrote it in the fly and there's probably few errors. Contrary to the clock last time, I focused on "how to do it" more that "it could be done like this". You don't have a base code yet, so it seemed to be the best way to answer. Anyway, you'll understand and remember it better if you wrote it by yourself.
 
Last edited:
  • Like
Reactions: Not Me

Zenathos815

Newbie
Jul 26, 2017
53
23
@anne O'nymous I have been playing with this one for a bit and I have adapted most of what you have added and I am trying to put together the character schedule that will be in the demo, in this I have decided to call the schedule "c0Schedule" because the character is "c" the full name will be later and "c0" is the name of the "Girl" class object where her stats are stored. I have a label that successfully adjusts certain stats but I have two questions, first I am trying to follow you on the object creation

You don't have permission to view the spoiler content. Log in or register now.

You don't have permission to view the spoiler content. Log in or register now.

Sorry I hope those questions make sense I have a bad habit of drinking and coding simultaneously, it makes bugs much more fun
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,145
14,829
I feel like it could be incredibly beneficial to integrate the scheduler into that class but I also feel that it would cause issues to integrate it completely so should it be separate to prevent them from bleeding into eachother?
So, why not both at the same time ? Yeah, I know, I need to explain it more than that...

Like you said, it's "incredibly beneficial to integrate" things like the scheduler directly into the class that define the characters. Whatever the way you make your game, you will need to know only one thing, "what's the object for this character". Once you have the answer, you can change everything you want related to this character.

You don't have permission to view the spoiler content. Log in or register now.

Now, if you have a separated object for the schedule, the problem is obvious, you have two questions: What's the object for this character, oh and by the way, what's the object for his schedule ?
You don't have permission to view the spoiler content. Log in or register now.

Now there's another problem, like you said, they can "[bleed] into each other". There's also the case where you have more that one kind of character, and need two different objects for the schedule, depending of the character ; by example schoolgirls are available every day, will teacher are out of the game during the week-end.
This tend to talk for the separated objects, but in fact the answer is a mix of both approach.
You don't have permission to view the spoiler content. Log in or register now.

Now for your first question... where to put the init, and also the "time to change/recompute the schedule" if needed... In fact it all depend of your game and yourself.
You don't have permission to view the spoiler content. Log in or register now.

And finally an advice :
Always follow your feelings, even if they seem like a bad practice. You are the one who wrote the code, so the one who'll have to remind, six month later, how things are done. If you go against your feelings, you'll fight against yourself and have hard time to remember what you've done and why you've done it like this. At the opposite, if you follow your feelings, you'll wrote the code that seem natural to you. So it will be easier to write it and to remember what, why and how.
But sometimes it's not this easy, like in the your second question were you had two contradictory feelings. In this case, try to make them coexist like I did here. The stats and schedule are in the same place, but still they are separated. Both your feelings are now in peace and the lines of code will come more easily in your mind.
 

Zenathos815

Newbie
Jul 26, 2017
53
23
@anne O'nymous That has to be the most zen coding advice I have ever gotten lol, I really appreciate this I will need to pm you a demo once I get this going. I will play with it and see what I can get to work based on your examples. I am actually looking at some of my code in different ways, I'm a slow thorough learner but I appreciate all the advice.

Once I get things taken care of from here, I will see if I can finish a couple character art sets and then work on the interface. Backgrounds are the biggest bitch as well as screens, UI has not been friendly either, but once I work a few of those things out I hope to start putting the demo together,

Also @Belle I actually took a look at some of the things I am doing and compared it to how you handled a few things and I think you may have made me rethink a few things that I was severely over-complicating. Namely my progression system that locks things off I was making totally separate labels for each stage when I could really use a true/false label to accomplish this, that way I am not re-writing the labels several times when they are essentially meant to do the exact same thing with extra features. You guys have been monumentally helpful. I'll shout if I run into anything else
 

Belle

Developer of Long Live the Princess
Game Developer
Sep 25, 2017
3,092
10,281
Glad to know I could be of at least a little help. I'm sorry if I can't be more actively helpful. I'm swamped in work on my own game right now.
 

Zenathos815

Newbie
Jul 26, 2017
53
23
Glad to know I could be of at least a little help. I'm sorry if I can't be more actively helpful. I'm swamped in work on my own game right now.
It's all good, I gave it a run I'm impressed with how seamless everything is and everything is very efficient! I think I am wracking my head on this so consistently because on all me previous game projects I was a writer and artist, I have always known bits of coding but it usually results in me talking to the actual coder saying "we should totally do something like this" I'm glad to be learning so much from you guys
 
  • Like
Reactions: Belle

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,145
14,829
You are all incredibly helpful. Thanks so much.
Well, if I can help, why not do it ? And I'm sure that's the same for many people here.
Plus, unlike @Belle (good game and code by the way), I'm not able to make a game since I still suck at the main part, the art. So, answering is a way to thanks and supports both those who make the games I like and those who make them available.