TCG Workaround for displaying your obtained cards

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
Baseliner88
Newbie
Posts: 7
Joined: Wed Feb 06, 2019 1:31 am
Contact:

TCG Workaround for displaying your obtained cards

#1 Post by Baseliner88 » Wed Feb 06, 2019 3:40 pm

Hi together,

i used this forum for over two years since i was getting started with RenPy.
Everytime i was stuck in my code, i found the perfect workaround here ^^

But now (stuck for about three weeks :shock: :? ) i'm running in circles and nothing i am figuring out is working.

To my person, i'm 30 years old from germany and no python professional...
I'm working with two friends on some kind of "screenbased Trading Card Game", one is designing and the other is writing the storyline and some kind of plot.

My job is the programmer part.

Routines like "Purchasing a Boosterpack" and "Card Battles" are already finished and working.

NOW COMES THE PROBLEM

I want to create a screen, where you see all your obtained cards, sorted by strengh.
-> Imagebuttons on a grid ...
-> Action when you click on one card ... Screenoverlay where you see the full card and an have the option to level it up

So what is done so far:
- I got a script where i got something like a database. Here are all carddetails written in a label

Code: Select all

label No1:
    $ name = "Beispielkarte001"
    $ attribut = "Feuer"
    $ hp = 100
    $ atk = 10
    $ grad = "Gewöhnlich"
    $ stern = 1
    if stern == 1:
    	$ bild = "Beispielkarte001a.png"
    elif stern == 2:
    	$ bild = "Beispielkarte001b.png"    	
    return

label No2:
    $ name = "Beispielkarte002"
    $ attribut = "Wasser"
    $ hp = 200
    $ atk = 20
    $ grad = "Gewöhnlich"
    $ stern = 1
    if stern == 1:
	$ bild = "Karte002a.png"
    elif stern == 2:
	$ bild = "Karte002b.png"
    return
Then i've some arrays to store the cards by grade (common, rare, epic, legendary)

Code: Select all

    $ count = 0
    while count != 11:
        $ count += 1
        call expression "No"+str(count)
        if grad == "Gewöhnlich":
            $ gewoehnlich.append(count)
        elif grad == "Selten":
            $ selten.append(count)
        elif grad == "Episch":
            $ episch.append(count)
        elif grad == "Legendär":
            $ legendaer.append(count)
That's for the boosterpackroutine...

Code: Select all

    menu:
        "Bronze Kiste":
            $ kcount = 0
            while kcount != 3:
                $ zufall = renpy.random.choice ( ('gewoehnlich', 'gewoehnlich', 'selten') )
                if zufall == "gewoehnlich":
                    $ zufall = renpy.random.choice((gewoehnlich))
                elif zufall == "selten":
                    $ zufall = renpy.random.choice((selten))
                $ erhalten.append(zufall)
                $ newcard = zufall
                call newcard
                $ kcount += 1
            $ zufall = ""
            pass
        "Silber Kiste":
            $ kcount = 0
            while kcount != 4:
                $ zufall = renpy.random.choice ( ('gewoehnlich', 'gewoehnlich', 'gewoehnlich', 'selten', 'selten', 'episch') )
                if zufall == "gewoehnlich":
                    $ zufall = renpy.random.choice((gewoehnlich))
                elif zufall == "selten":
                    $ zufall = renpy.random.choice((selten))
                elif zufall == "episch":
                    $ zufall = renpy.random.choice((episch))
                $ erhalten.append(zufall)
                $ newcard = zufall
                call newcard
                $ kcount += 1
            $ zufall = ""
            pass
        "Gold Kiste":
            $ kcount = 0
            while kcount != 5:
                $ zufall = renpy.random.choice ( ('selten', 'selten', 'selten', 'episch', 'episch', 'legendaer') )
                if zufall == "selten":
                    $ zufall = renpy.random.choice((selten))
                elif zufall == "episch":
                    $ zufall = renpy.random.choice((episch))
                elif zufall == "legendaer":
                    $ zufall = renpy.random.choice((legendaer))
                $ erhalten.append(zufall)
                $ newcard = zufall
                call newcard
                $ kcount += 1
            $ zufall = ""
            pass
        "zurück":
            pass
This is the boostercardroutine, where you get a random card out of the three diffrent boosterpacks.

What I want to do now, is creating an array where I store all obtained cards.
"If card == obtained:
append to array"
But i need to give this list the label number like

Code: Select all

call expression "No"+str(count)
and also the strengh of the card.

In the second step i would fill this array into an other one:
why?
Because i want to sort it like:
"array1.max(strengh).append to array2"
and after that i need to remove the actual index from the array1.
So I would get a loop till the array1 is empty and sorted into array2.

After that i need to fill array2 into some kind of grid with imagebuttons on a screen.

After that is done, placeholders with grey cards should appear in the rest of the grid.
So if you obtain 30 of 100 cards, 30 cards should be displayed as imagebuttons sorted by strengh and after the weakest card the 70 grey not obtained cards should appear.

That system should be easily expanding if more cards come with updates in future.

OMG, hope someone can give me a suggestion by this mess :?:
Sorry for typos and the "not so professional" english.

Please help me.

Best regards
Baseliner

philat
Eileen-Class Veteran
Posts: 1656
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: TCG Workaround for displaying your obtained cards

#2 Post by philat » Wed Feb 06, 2019 8:40 pm

Er... I would not recommend trying to do a TCG without at least a beginner level of knowledge re: classes and OOP...

viewtopic.php?f=51&t=44730

The above is a pretty good primer (it's for items and inventory, but that's really the same thing as cards and a deck).

Baseliner88
Newbie
Posts: 7
Joined: Wed Feb 06, 2019 1:31 am
Contact:

Re: TCG Workaround for displaying your obtained cards

#3 Post by Baseliner88 » Thu Feb 07, 2019 1:42 am

Hi, thx for your reply.

I knew this threat and yes, i think i got a beginner level of knowledge. But there must be a much easier way du do that. Without creating a card class and the inventory for the obtained ones.

Also, there would be the Problem with the class workaround, that you don't get a clear overview of all possible cards in the script. So balancing would be much more difficult to realise.

In my opinion, labes ("as some kind of class") are totaly enough. That isn't such tricky like an inventory with amount and too much weight.
The cards are extremly static, not really variable values in it. And the bit that changes can be realised in an if-clause Inside the label.

Problem is just with the array to array filling / sorting and than displaying.

philat
Eileen-Class Veteran
Posts: 1656
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: TCG Workaround for displaying your obtained cards

#4 Post by philat » Thu Feb 07, 2019 1:48 am

...yeah, I literally have no idea how you're setting this up, so I got nothing. Good luck; hope someone else can help.

Human Bolt Diary
Regular
Posts: 99
Joined: Fri Oct 11, 2013 12:46 am
Contact:

Re: TCG Workaround for displaying your obtained cards

#5 Post by Human Bolt Diary » Thu Feb 07, 2019 2:56 am

I'm going to second what philat said and give you a strong recommendation to learn how to use classes and for loops. You definitely don't seem to have enough programming knowledge or python experience, so you should practice that. I would read the link he gave you and think of how to solve your issue in an OOP way.

Something like:

Code: Select all

$ kcount = 0
            while kcount != 3:
                $ zufall = renpy.random.choice ( ('gewoehnlich', 'gewoehnlich', 'selten') )
                if zufall == "gewoehnlich":
                    $ zufall = renpy.random.choice((gewoehnlich))
                elif zufall == "selten":
                    $ zufall = renpy.random.choice((selten))
                $ erhalten.append(zufall)
                $ newcard = zufall
                call newcard
                $ kcount += 1
            $ zufall = ""
            pass
Can easily be simplified with a for loop:

Code: Select all

python:
    for _ in range(3):
        a = renpy.random.choice ([gewoehnlich, gewoehnlich, selten])
        zufall = renpy.random.choice(a)
        erhalte.append(zufall)
        renpy.call(zufall)

Baseliner88
Newbie
Posts: 7
Joined: Wed Feb 06, 2019 1:31 am
Contact:

Re: TCG Workaround for displaying your obtained cards

#6 Post by Baseliner88 » Thu Feb 07, 2019 3:14 am

If you all really think so ... It must be true :-(

I know object orientated pragramming class management but wanted to avoid it. In my opinion it's to huge for some kind of scripting (not the lines, meant more by OOP as a weapon). But seams to be nessesary to realise my Problem.

Thanks for opening my eyes.

Baseliner88
Newbie
Posts: 7
Joined: Wed Feb 06, 2019 1:31 am
Contact:

Re: TCG Workaround for displaying your obtained cards

#7 Post by Baseliner88 » Wed Feb 13, 2019 6:44 am

Ok, here am I again...

I followed your advice and built my scripts object orientated.
Everything works fine,

BUT

I am hanging at a "sorting loop".

Code: Select all

    
    call screen sammlung
    screen sammlung:                    ### Calling the screen were all cards are displayed
        for i in (komplett):
            if i.vorhanden == True:     ### Searching only the cards the have been obtained
                $ sammlung.append(i)
            else:
                pass                    	### !!!Here in between I want to sort be a variable of the object card called strengh

        for i in (komplett):            ### Listing the rest of possible cards which are not obtained
            if i.vorhanden == False:
                $ sammlung.append(i)
            else:
                pass

        vpgrid:
            cols 5
            spacing 15
            xalign 0.5
            ypos 10
            mousewheel True
            scrollbars "vertical"

            for i in (sammlung):        ### getting the cards displayed in a vpgrid and only the obtained ones are colored
                if i.vorhanden == True:
                    imagebutton idle im.Crop(i.bild, (0,0,200,200)) action Hide("sammlung"), Return()
                if i.vorhanden == False:
                    imagebutton idle im.Grayscale(im.Crop(i.bild, (0,0,200,200))) action Hide("sammlung"), Return()

Just for explanation:
komplett [] = all possible cards
sammlung [] = the screen where you can see your obtained cards sorted by strengh (staerke)
Inside the arrays are the objects from class "Karte".

Code: Select all

    class Karte(object):
        def __init__(self, vorhanden, bild, nummer, name, grad, sterne, attribut,staerke, atk, hp):
            self.vorhanden = vorhanden
            self.bild = bild
            self.nummer = nummer
            self.name = name
            self.grad = grad
            self.sterne = sterne
            self.attribut = attribut
            self.staerke = staerke
            self.atk = atk
            self.hp = hp
I was trying the sort() function, even some kind of "bubble sort" ... everything without positive effect.

Sorry for my cruel german/english scripting :oops:

Someone got a suggestion for me?
Thanks in advance.


Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot], Newnewbie