Lemma Soft Forums

Supporting creators of visual novels and story-based games since 2003.


Visit our new games list, blog aggregator, IRC, and wiki.
Activation problem? Email [email protected]
It is currently Thu May 23, 2013 7:19 am

All times are UTC - 5 hours [ DST ]


Forum rules


Ask questions about one topic per thread, and use a descriptive subject. "NotImplemented error in script.rpy" is a good subject, "Tom's problems" is not. Remember to include all of traceback.txt or error.txt when reporting a problem, as well as the relevant lines of script. Use the [code] tag to format scripts.



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Apr 11, 2012 1:33 pm 
Regular
User avatar

Joined: Wed Dec 01, 2010 7:43 pm
Posts: 164
Location: British Columbia
Projects: Sprite Art for: "Final Banquet", "365 Days"
To me, the subject looks like nonsense. I don't know the jargon, or rather, have forgotten it since not working with any sort of code for well over a year.

I wasn't sure how to search for what I wanted to know, or even how to ask this.

Is there a way to set it up so new variables or "objects" are made with some sort of serial number attached?

Let us pretend I have a game that involves collecting Easter Eggs.

If I already have:

$ eggcol = ["pink", "yellow", "blue", "purple", "green"]
$ eggsfound = []

$ Egg1 = "pink"
$ Egg2 = "blue"
$ Egg3 = "yellow"

But then what if I wanted the Easter bunny to randomly lay more eggs, or have an event that triggers laying more unique eggs? So that I don't have to type in a long list of egg1, egg2, egg3, it makes egg4, egg5, and egg6 for me when it is needed? And that it will also assign one of the listed colours to this new, unique egg? And perhaps other attributes, like "sparkly" or "hatchable" or something...

So something like... um...

Code:
label search:
     "You search for eggs."
     call find
     if find = True:
        "AHA!"
        call newegg
        "You found an egg!"

     else:
         jump nofind

label find:
    $find = renpy.random.randint(1,100)
    if find >= 50:
        return True
    else:
        return False

label newegg:
     (Code for generating egg# then appending it to list of collected eggs)
label nofind:
    "You fail to find an egg. Try again?"
    menu tryagain:
        "Yes.":
             jump search
        "No.":
             jump stop

label stop
    etc etc


At some point, the list of eggs can be viewed, and selected for more information, such as it's colour, pattern, or some other attribute.

Is this possible?

Would the following work?

$ egg%(serial)d = renpy.random("eggcol")

where $ serial is defined by a counter that constantly adds one each time there is a successful find?


Top
 Profile Send private message  
 
PostPosted: Wed Apr 11, 2012 5:19 pm 
Ren'Py Creator
User avatar

Joined: Mon Feb 02, 2004 10:58 am
Posts: 10776
Location: Kings Park, NY
Completed: Moonlight Walks
Projects: Ren'Py
I think you probably want a list here, rather than a series of variables. So you could then do:

Code:
$ eggs = [ ]

# ...

$ eggs.append(renpy.random.choice(eggcol))

# ...

if len(eggs) >= 2 and egg[1] == "red":
    "The second egg is red!"

_________________
Another Old-Fashioned Bishoujo Gamer
Supporting creators since 2004; Code > Drama
(When was the last time you backed up your game?)
"It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face in marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming" - Theodore Roosevelt


Top
 Profile Send private message  
 
PostPosted: Wed Apr 11, 2012 9:52 pm 
Regular
User avatar

Joined: Wed Dec 01, 2010 7:43 pm
Posts: 164
Location: British Columbia
Projects: Sprite Art for: "Final Banquet", "365 Days"
Ah I was imagining that might be what someone would respond with... sometime after i posted. I used a really bad example rather than saying exactly what I want to do, but I tend not liking to share exactly what I'm up to because I like being all mysterious.

But mysterious and vague people don't get help, so I'll suck it up.

What I'm doing is more complex than eggs with colours. It's rats. Rats with colours. Rats that can breed and make new rats.

What I have set up is a Rat class, with attributes I defined myself, such as colour, gender, value (because there will be buying and selling of rats). So I have this:

Code:
init python:

    class Rat:
        def __init__(self, name, age, gender, health, furcol, gene1, gene2, worth):
            self.name = name
            self.age = age
            self.gender = gender
            self.health = health
            self.furcol = furcol
            self.gene1 =gene1
            self.gene2 = gene2
            self.worth = worth

    class Own:
        def __init__(self, funds=100):
            self.funds = funds
            self.Rat = []


And then later on...

Code:
python:
        own = Own()
        Rat1 = Rat("Pepper", 3, "Female",10, "black", "B", "b", 100)
        Rat2 = Rat("Angel", 2, "Female", 8, "white", "b", "b", 150)
        Rat3 = Rat("Sable", 5, "Male", 9, "black", "B", "B", 100)
        Rat4 = Rat("Salt", 4, "Male", 10, "white", "b", "b",150)


When I breed them, is there a way I can have it generate a Rat5 that pulls its attributes from defined parameters? So that it does a coin toss for gender, and then assigns either B or b depending on what the parents have? I'm doing a thing on very basic Mendellian heredity and displaying it through a game rather than a lengthy paper with a series of punnet squares.


Top
 Profile Send private message  
 
PostPosted: Wed Apr 11, 2012 10:08 pm 
Ren'Py Creator
User avatar

Joined: Mon Feb 02, 2004 10:58 am
Posts: 10776
Location: Kings Park, NY
Completed: Moonlight Walks
Projects: Ren'Py
I think the question is - how would you use Rat5 if it was defined? It's certainly possible to write the code:

Code:
$ Rat5 = breed(Rat1, Rat2)


but that wouldn't extend to Ratn. If you want a non-fixed number of rats, you need a list.

_________________
Another Old-Fashioned Bishoujo Gamer
Supporting creators since 2004; Code > Drama
(When was the last time you backed up your game?)
"It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face in marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming" - Theodore Roosevelt


Top
 Profile Send private message  
 
PostPosted: Thu Apr 12, 2012 9:06 am 
Regular
User avatar

Joined: Wed Dec 01, 2010 7:43 pm
Posts: 164
Location: British Columbia
Projects: Sprite Art for: "Final Banquet", "365 Days"
Rats (pun intended). Oh well.

I might try attacking this from a completely different angle. Thanks for the prompt replies!


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: Google [Bot]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Protected by Anti-Spam ACP
Powered by phpBB® Forum Software © phpBB Group