This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

How to properly structure this kind of rpg/card game mix?

I'm trying to create a system of 'cards', where every card is an event in the game world. These cards will come in sequences, of about 10, and the idea is that each card will be able to do anything to the game's data (will keep it in a single dictionary with arrays and other dictionaries nested inside it). Now, I don't want a system where each card is it's own .gd file, because the idea is to have thousands of cards, most of them doing simple stuff, so I want a single .gd file to store a single sequence of cards, or eventually multiple sequences.

I have already found two ways of doing this, but both suck in different ways.

First one: http://pasteall.org/84909/python The cards are Objects with functions and arguments stored as strings. When the card is run, the functions are run using call(). Sucks because I can only do simple stuff that way, cards can't create temporary variables, do if/else statements, math etc.

Second one: http://pasteall.org/84911/python The card sequence is just a long if/else statement. Sucks, because the card sequence is just a long if/else statement.

Anyone knows an alternative to these methods? Any help appreciated.

Best Answer

  • PLyczkowskiPLyczkowski Posts: 3
    Accepted Answer

    After discussing this a bit on irc I finally went with storing the sequence of cards in a scene file (.tscn) as Nodes extending a single "card.gd" file, that contains some basic functionality, with embedded script in each Node. This way they all can fire any code, like in the if/else example, I have 1 file per sequence, and an additional benefit of a visual tree structure for the Nodes (using parenting), which I can use for non-linear card flow.

Answers

  • SakakiSakaki Posts: 30Member

    In the example of the "boy/girl" card you can simply make a variable to store the value and keep the card as it is, just changing the var gender (?) on the strings.

    Also for a card object you can export some variables on an array to choose each kind of data the card will handle. For example:

    export (String, "Name", "Damage", "Armor") var effect.

    Then the code can search the dictionary for the given param selected by you. I'll be honest, I don't have any idea of programming/coding but this seems to be a good OOP approach, since the code itself will not change much and you'll be able to make children/instances that inherit the basic bard behaviour.

  • PLyczkowskiPLyczkowski Posts: 3Member
    Accepted Answer

    After discussing this a bit on irc I finally went with storing the sequence of cards in a scene file (.tscn) as Nodes extending a single "card.gd" file, that contains some basic functionality, with embedded script in each Node. This way they all can fire any code, like in the if/else example, I have 1 file per sequence, and an additional benefit of a visual tree structure for the Nodes (using parenting), which I can use for non-linear card flow.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.