Check object types

Discussion and feedback on Construct 2

Post » Wed Sep 19, 2012 9:58 am

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.    
B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Wed Sep 19, 2012 11:40 am

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,574

Post » Wed Sep 19, 2012 12:12 pm

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.   
B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Thu Sep 20, 2012 8:00 am

So, is there any hope for this sort of functionality?
B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Thu Sep 20, 2012 1:54 pm

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?
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,574

Post » Thu Sep 20, 2012 3:53 pm

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:

https://www.dropbox.com/s/vc4o6cn0ibu06s5/create_family_member.capx
B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Thu Sep 20, 2012 7:29 pm

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
B
79
S
24
G
54
Posts: 4,743
Reputation: 40,749

Post » Thu Sep 20, 2012 10:09 pm

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) xoros2012-09-24 10:55:45
B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Mon Sep 24, 2012 11:06 am

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.
B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Fri Sep 28, 2012 11:47 am

@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.
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 14 guests