0 Favourites

Check object types

  • Hi, I know there's no work around for this problem, but I would like to address this issue again and hear what do you think about it.

    I'm developing a game, which distantly resembles mahjong in the game mechanics. During the game a lot of game tokens (many different game pieces, power ups, special cards, bonuses etc.) are generated on run time, to some extend randomly. A lot of actions are performed on single tokens. I have like a main family "Cards", which has many children (game pieces) with different characteristics. As the game grows, writing game logic for creating this family instances on run time and performing actions on them is pure nightmare: I have to duplicate the same "code" for like 50 different family members again and again. After this breaking change in version 101 it got even worse. In order to make simple logic (which would be like 2-3 lines of code in AS3) I have to struggle with work arounds for hours.

    One feature would solve all this problems easily - it is accesing object types by name directly (like create "SpriteXYZ") and not through editor dialogue only. I read, that right now it's not possible because the code could not be obfuscated properly (you would see the objects name in the code). I can't believe, that there'S no solution for that.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Are you sure you're using families properly? The whole point of families is you can make events once for the entire family, rather than repeating the events 50 times.

  • For example I want to create one certain member (object type) of the family "Cards" - "card_green". I can't do it like this:

    create "Cards" and than point to a certain member "card_green", because I can't pass object type directly from a variable, so have to create hard coded conditions for each possible family member: if var Obj=1 create "Green", if var Obj=2 create "Red" etc. It's also not possible to make reusable logic because of that.

  • So, is there any hope for this sort of functionality?

  • You just need a set of subevents at the specific point you create an object. There's no need to duplicate all your events. That should still be manageable, right?

  • Hmm, I can't imagine how to do it another way. May be there's an in depth tutorial on this topic or documentation? Here's the .capx, where I've tried to illustrate the problem:

    dropbox.com/s/vc4o6cn0ibu06s5/create_family_member.capx

  • Simplified, your events would look like this:

    http://dl.dropbox.com/u/5426011/fixed/xoros.capx

    You can also reduce object creation down to one event by using a different animation per card/tile instead of a different object:

    http://dl.dropbox.com/u/5426011/fixed/xoros2.capx

    Or you can use a different animation frame per card/tile but the concept is the same:

    http://dl.dropbox.com/u/5426011/fixed/xoros3.capx

  • Thank you R0J0hound,animation solution is a good work around, but I think it could have some limitations for more complex objects (e.g. objects with different dimensions, multiple animations) and if you have a lot of objects in the game it will be hard to manage them.

    Another problem is perfoming actions on each newly created object. In this particular example - how to make each object reach each destination (the problem is - every time you click on create new object, movement of the prevous one is interrupted)

  • Is it possible to solve the issue by developing a plug-in/behavior which will enable creating object types by name? E.g. it could be a behavior with the property "Name", which could be accessible through object creation method.

    Or it could be a plug-in "Object", which can hold any object type (Sprite,Text, Button etc) and has it's own object creation method with "object name".

    I have a limited JS Knowledge and don't know anything about Plugin API, but if it's possible I will work into it.

  • xoros

    It could not "create instance by name", because that C2 will change the sprite name after export.

    "it could be a plug-in "Object", which can hold any object type (Sprite,Text, Button etc) and has it's own object creation method with "object name"."

    It might be possible, to use tag (string) to replace the object type.

  • So basically this plugin would have its own method "create object by tag"?

  • xoros

    Yes, before using "create object by tag", user should register tag with object.

  • Another problem is perfoming actions on each newly created object. In this particular example - how to make each object reach each destination (the problem is - every time you click on create new object, movement of the prevous one is interrupted)

    You can use an instance variable to identify each object/frame that is created. I do this for my current project.

    So, when object is created [e.g. green_card], you can have the instance variable (IV) set to a new number. You can then use this IV number to identify only that card. Likewise, if different families or groups of cards move to the same location/in the same manner, you can set each new instance of that card/object with the same IV.

    Or, if you don't want to set each one manually, you can have a global variable (GV) track the progress of these cards (e.g. create green_card -> +1 to GV). You can then have each IV set to the GV, and use this as a unique card identifier.

    So it would look like this:

    On Create Green_Card;

         Change GV by +1

         Set IV to GV    --> NOTE: this might need to be an empty subevent,

                                       or one additional indentation

    AND

    If Green_Card IV = (x)

         Move Green_Card to (x,y)

    Something like that.

  • xoros

    I'll try to make a plugin from your requirement about creating object by tag if you want.

    The first step, you need to write down your requirement.

  • Cool, that will be usefull!

    I'll try to define a requirment:

    I think it will make sence to implement it as a behaviour, which can be added to basic object types (like families, sprites, tiled backgrounds, text etc.) Methods of the behaviour could be accesed through actions dialogue. Tag could be defiened in the behaviour properties or by an action.

    In the actions menu there are 3 methods

    1) Create object by tag

    2) Set objects tag name

    3) Pick objetc by tag (if it makes sence)

    rexrainbow, thanks for your help

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)