No need to apologize at all, I actually super appreciate the corrections. So, I'm having a bit of a hard time understanding and part of it is that there is 18+ stuff in the code and so every time I've posted problems I've had to go through and change everything to make it PG, but due to that it becomes kinda hard to understand and follow. It's actually waaaay easier to follow in its original format, but I cannot use both the code and spoiler tags at the same time so it's just impossible to share in the questions forum without like, accidentally blindsiding innocent passerby.
I can't see any solution to that, so I'll just do my best to go over my code a bit more in depth and maybe try to figure out how to restructure this better? (Just didn't really understand the way it was phrased before, which is just on me being derpy.)
First, I have this really huge class for NPC generation. NPCs have a ton of different variables and stuff, so within each NPC I can change a bunch of different variables. (And different variables interact with each other.)
To get an idea of how the character generator works, here's a few pieces of it:
Code: Select all
init python:
partnerno = 0
class NPCList():
def __init__(self, racelist, typelist, procaselist, level):
self.race = renpy.random.choice(racelist) #Random race as determined by the area
if self.race == "human" or self.race == "elf":
self.racesize = 2
elif self.race == "gnome":
self.racesize = 1
elif self.race == "fairy":
self.racesize = 0
elif self.race == "ogre":
self.racesize = 3
elif self.race == "centaur":
self.racesize = 4
elif self.race == "giant":
self.racesize = 5
elif self.race == "demon" or self.race == "spirit":
self.racesize = renpy.random.randint(0,5)
else:
self.racesize = -1
To generate my NPCs, I literally just do this:
$ npc_dict = GenerateMultipleNPCs(3)
the number being how many I'm generating.
This will end up with me having something that is like this: npc_dict = [npc1, npc2, npc3]
It all works pretty much identical to what you did with the What(object) class, it's just more filled in.
I have a few different labels that feed into each other, allowing me to get a replayable "combat" type turn based mechanic. It basically goes like this:
Map (player moves to a new grid/square on the map)
v
event checker
v
event label
v
combat_start label (this is really more of the frame for everything)
v
next_turn label (changes variables every turn based on conditions, checks to see if you've met requirements for ending combat)
v
keep doing next_turn until conditions met for ending combat, then...
v
combat_finish label
v
goes back to combat_start and resets all necessary variables before exiting back to the map.
The code I'm working on is basically, inside the next_turn label, every turn there is a description of the NPCs actions and the player's actions for that turn. This is pretty elaborate, as npcs have different personality types that make them act different under different conditions and there's a bunch of different sections of the code for different actions they can take. (They don't necessarily only take one action per turn, they can take multiple actions under different conditions.)
I was originally considering rewriting everything so that the loop was inside the action description label, which seems like that's what's going on with that while loop you mentioned, but found that it was faster and easier to just loop the description label instead. Since everything is really elaborate, I'm not actually sure how much space/efficiency I'd save by switching to doing it that way? Also, I don't have any python blocks inside the action description, I only have it prior to the for loop. (But, if I used while, I understand I wouldn't need python at all, I just don't feel one small python block is in the way?)