[ RESEOLVED ] Renp'y Classes / Game objects
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.
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.
[ RESEOLVED ] Renp'y Classes / Game objects
Hey Everyone.
I'm still learning renpy and my background is mainly c#, c++ and back in the day when they were still relevant Pascal and Basic.
Im trying to work out if object oriented programming is possible in renpy as all the guides that I've seen for some of the things I want to code seem to use nested arrays which to me seems like messy coding.
Is it possible to define a class in Renpy in the same way that I would do in another language and then instantiate it? for example if I wanted to define an NPC in another compiler all i would do is define the NPC class with a set of properties such as level, Hit points, attack power and then just instantiate it for every npc I cant work out how to do that in renpy,
any help would be greatly appreciated
I'm still learning renpy and my background is mainly c#, c++ and back in the day when they were still relevant Pascal and Basic.
Im trying to work out if object oriented programming is possible in renpy as all the guides that I've seen for some of the things I want to code seem to use nested arrays which to me seems like messy coding.
Is it possible to define a class in Renpy in the same way that I would do in another language and then instantiate it? for example if I wanted to define an NPC in another compiler all i would do is define the NPC class with a set of properties such as level, Hit points, attack power and then just instantiate it for every npc I cant work out how to do that in renpy,
any help would be greatly appreciated
Last edited by Thundy on Fri Dec 29, 2017 10:52 am, edited 1 time in total.
Re: Renp'y Classes / Game objects
Sure. It's all python. General example: viewtopic.php?f=51&t=44730
Re: Renp'y Classes / Game objects
awesome thanks
Re: Renp'y Classes / Game objects
[Deleted]
Last edited by Thundy on Fri Dec 29, 2017 6:17 am, edited 1 time in total.
Re: Renp'y Classes / Game objects
Ok so it turns out my array wasnt working properly. THe code was compiling but threw an exception later on
here is the code im trying to make work
and then accessing it
Ive removed most of the text formatting to make it easier to read
here is the code im trying to make work
Code: Select all
python:
class quest(object):
def __init__(self, title, description, isActive, isComplete):
self.title = title
self.description = description
self.isActive = isActive
self.isComplete = isComplete
$ goals[50] = quest('','', False, False)
$ goals[1].title ="No place like home"
$ goals[1].descrtiption="Find somewhere for your family to live"
$ goals[1].isActive=True
$ goals[1].isComplete=False
Code: Select all
for i in goals:
if goals[i].isActive:
if goals[quest].isComplete:
text "{alpha=0.2}[goals[i].title]{vspace=12}[goals[i].description]{/alpha}{vspace=25}"
else:
text "[goals[i].title]{vspace=12}[goals[i].description]{vspace=25}"
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Renp'y Classes / Game objects
if goals[quest].isComplete:
I think you wanted goals[ i ] there, especially as quest is a mutable class object so cannot be a dictionary key... unless you have also defined quest as a variable name, which would not be an advised route
Personally, rather than using goals[ i ] all over the place, maybe
for q in goals.values(): # or goals.items() ... if goals is a dictionary (which I presume from the goals[ i ] bits)
or
for i,q in enumerate( goals ): # i = index, q = value (aka a quest object)... this is if goals is a list and not a dict
Also remember/note: dictionary keys are unsorted... for i in goals is not guaranteed to return them in the same order each time
Hard to say more without seeing more code
I think you wanted goals[ i ] there, especially as quest is a mutable class object so cannot be a dictionary key... unless you have also defined quest as a variable name, which would not be an advised route
Personally, rather than using goals[ i ] all over the place, maybe
for q in goals.values(): # or goals.items() ... if goals is a dictionary (which I presume from the goals[ i ] bits)
or
for i,q in enumerate( goals ): # i = index, q = value (aka a quest object)... this is if goals is a list and not a dict
Also remember/note: dictionary keys are unsorted... for i in goals is not guaranteed to return them in the same order each time
Hard to say more without seeing more code
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
Re: Renp'y Classes / Game objects
{Deleted}
Last edited by Thundy on Fri Dec 29, 2017 10:10 am, edited 1 time in total.
Re: Renp'y Classes / Game objects
So my new declaration is as follows
Which works. I was being a bonehead with my array declaration. I can now just add quests to the array but the function that reads them is throwing up an exception about indices needing to be integer and not unicode.
the exception is in the text lines
Code: Select all
python:
class quest(object):
def __init__(self, title, description, isActive, isComplete):
self.title = title
self.description = description
self.isActive = isActive
self.isComplete = isComplete
goals = [ ]
goals.append(quest("No place like home", "Find somewhere for your family to live", True, False))
Code: Select all
for i,q in enumerate(goals):
if goals[i].isActive:
if goals[i].isComplete:
text "[goals[i].title]{vspace=12}[goals[i].description]"
else:
text "[goals[i].title][goals[i].description]"
Re: Renp'y Classes / Game objects
OK sorry for bumping my own thread but i solved my issue
The solution was simple enough, it was mostly me being stupid
the working code is as follows. please feel free to use it you stumbled on this trying to figure it out
and then
obviously text formatting will be used to make the completed quest look different from the uncompleted one.
The solution was simple enough, it was mostly me being stupid
the working code is as follows. please feel free to use it you stumbled on this trying to figure it out
Code: Select all
python:
class quest(object):
def __init__(self, title, description, isActive, isComplete):
self.title = title
self.description = description
self.isActive = isActive
self.isComplete = isComplete
goals = [ ]
goals.append(quest("No place like home", "Find somewhere for your family to live", True, True))
Code: Select all
for i,q in enumerate(goals):
if q.isActive:
if q.isComplete:
text "[q.title]{vspace=12}[q.description]{vspace=25}"
else:
text "[q.title]{vspace=12}[q.description]{vspace=25}"
- Milkymalk
- Miko-Class Veteran
- Posts: 753
- Joined: Wed Nov 23, 2011 5:30 pm
- Completed: Don't Look (AGS game)
- Projects: KANPEKI! ★Perfect Play★
- Organization: Crappy White Wings
- Location: Germany
- Contact:
Re: [ RESEOLVED ] Renp'y Classes / Game objects
Glad you figured it out!
My advice is to say goodbye to the word "array". Like you, I came from Basic and Pascal and this word as well as "record" (shudder) kept me from understanding data structured in Python.
There are no arrays, there are only lists.
And dictionaries, And tuples. And sets.
Lists basically work like arrays, but they bring their own methods to manipulate them. Also, arrays in Basic and Pascal need to be declared and have a fixed length. A list is the most flexible way to store data that I have ever seen.
Also, make it a habit to capitalize class names, it's how it's usually done. That way you and everybody who reads your code will know that "Quest" is the class name and "quest" is just one instance of that class (if you decide to do "quest = Quest()").
You don't need to enumerate if you never use that number. Just do:
My advice is to say goodbye to the word "array". Like you, I came from Basic and Pascal and this word as well as "record" (shudder) kept me from understanding data structured in Python.
There are no arrays, there are only lists.
And dictionaries, And tuples. And sets.
Lists basically work like arrays, but they bring their own methods to manipulate them. Also, arrays in Basic and Pascal need to be declared and have a fixed length. A list is the most flexible way to store data that I have ever seen.
Also, make it a habit to capitalize class names, it's how it's usually done. That way you and everybody who reads your code will know that "Quest" is the class name and "quest" is just one instance of that class (if you decide to do "quest = Quest()").
You don't need to enumerate if you never use that number. Just do:
Code: Select all
for q in goals:
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Re: [ RESEOLVED ] Renp'y Classes / Game objects
Thanks Milky. Sorry for the slow reply. life etc
Who is online
Users browsing this forum: No registered users