How do I know which instance has which IID?

Get help using Construct 2

Post » Wed Jan 11, 2012 9:26 am

nope I think you summed up things nicely. Although I think the second one is really what you were looking for.
What I mean is, in a way, setting an instance variable and putting a distinctive value during edit time (what you call build time) is semantically the same as naming an instance.
So using a condition to pick this proper instance is, in my opinion, exactly the same as doing a:
[code]if(instance.name == "black")
{
instance.favorite = true;
}[/code]Yann2012-01-11 09:26:29
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Jan 11, 2012 7:11 pm


@Yann: Many thanks for your positive feedback.

Yes, your code is semantically the same as the Construct 2 code. But that's not what I'd do in JavaScript. Instead, I'd write:

[CODE]var instance = new ObjectType();
...
instance.favorite = true;[/CODE]
... which is both semantically and syntactically different. There's no longer any dependence on the condtional test of an instance variable. That's why I called the Construct 2 solution a workaround.

In fact, I'd go further and call it a kludge, and like all kludges it has a real downside. In this case, it's that the assignment depends on the value of a variable, which is always vulnerable to change. There's no such problem with a named instance, of course - the name is the identifier of its essence and simply can't be changed.

@newt: I'm sorry. I don't get your point.Velojet2012-01-12 00:57:43
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Wed Feb 06, 2013 11:39 pm

Hi Velojet,

I wouldn't normally bother bringing up a post that is over a year old, but it has been listed in the General FAQ and I wouldn't want people new to the platform to be misinformed about the design of Construct 2's event system.

As you're aware, Construct 2's events allow users to "Pick" one or more objects implicitly, rather than assign specific objects to variable names, as you would in a language like Javascript. This is no more a kludge than how the "this" keyword in Javascript is implicitly assigned within a function to a particular object based on how the function was called. They are meant as conveniences. There's a very popular language used to sort, filter, and modify tables of data, called SQL, which behaves very similarly: you ask it to select rows based on the contents of the rows, and then you tell it what to do with each of those rows. SQL does this job wonderfully, and to do the same using Javascript with objects, arrays, and for loops all over the place would be a nightmare. It would feel like a kludge.

Javascript is not the ultimate language. Nor is SQL, C++, C, or even Assembly. The purpose of a programming language is to translate human intention into something a computer can act on. Yes, depending on your needs, it may be difficult or impossible to do what you want with just Construct 2 events, and in that situation, you may need to move to Plugins so that you can code it in Javascript. But for the most part, Construct's method of implicit selection and foreach-style actions is a very powerful and more natural way of expressing intent for the sort of things we want it to do. It only starts to feel like a kludge if you insist on writing your events in the same style you would write Javascript code.

Anyway, I hope you get my point. There are many ways to represent your intent to a computer, and depending on the language chosen, some intents will be easy to express while some will be hard. I always recommend learning more languages (C, Java, Javascript, Lisp, SQL, RegEx) so that one can have a broader understanding of what tools we have available to us as programmers.
B
6
Posts: 26
Reputation: 577

Post » Thu Feb 07, 2013 8:41 am

@Cowdozer
Thanks for keeping this discussion alive!

RegEx a language? Isn't it a pattern matching mechanism that's implemented in many languages (even SQL)?
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Fri Feb 08, 2013 9:57 am

Yep and yep. It's certainly not a Turing complete language (you can't make it do everything), but it's a great example of a domain-specific language. For Regular Expressions, its domain is pattern matching and replacing text. I'm not sure if SQL has RegEx support... I know there is a LIKE clause, which uses a simple (but non-RegEx) syntax. But Javascript definitely has RegEx, and it makes parsing strings very easy compared to using nested for loops, if statements, and variables pointing to different indices. It's not going to blow your mind in the same way that Lisp might blow a Java programmer's mind, but it is a prime example of why learning more languages gives you more effective tools as a programmer.

BTW, I see that you've done a plugin tutorial video! That's greatly appreciated, and I'm going to have to check it out soon. :)
B
6
Posts: 26
Reputation: 577

Post » Fri Feb 08, 2013 6:14 pm

@Cowdozer
Definitely not a programming language in the same category as C, Java, Javascript, Lisp and SQL.In fact, I think you'd be hard put to find any authority describing it as a language.

[QUOTE=Cowdozer]... I'm not sure if SQL has RegEx support ...[/QUOTE]
See, e.g., www.ibm.com/developerworks, www.regular-expressions.info, ...Velojet2013-02-08 18:39:04
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Sat Feb 09, 2013 3:37 am

On Wikipedia's definition of "Programming Language":
[quote]A programming language is a notation for writing programs, which are specifications of a computation or algorithm. Some, but not all, authors restrict the term "programming language" to those languages that can express all possible algorithms.[/quote]

So yes, it is debatable as to whether RegEx is a language since it's not Turing complete (but neither is plain SQL). I agree that RegEx and SQL are not at all in the same category as the others we've listed, but I personally don't mind if someone calls them programming languages or something else. I did not intend to be misleading by using that term.

Thanks, I see from your links that Oracle's databases have functions and in IBM DB2 you can add user-defined functions. Definitely worth using if you have a need for it and aren't worried about making your SQL queries slightly platform-dependent.

I watched your Plugin tutorial and it was a nice intro. :) Construct 2 seems very easy to extend that way!
B
6
Posts: 26
Reputation: 577

Post » Sat Feb 09, 2013 6:36 am

instead of starting a new thread I have a similar thing I'm trying to figure out. I have 32 sprites on the layout all of which are stationary. I kneed to change the active frame of the one clicked and cannot figure out how to set the frame on a sprite based on uid of the one clicked. Trying to avoid using 32 sprites. They are for buildings and clicking on one upgrades it so I need to know exactly which one was clicked

only been working with Construct 2 for 3 days so reply in very beginner terms :)
Thanks for any help
B
6
S
1
G
1
Posts: 19
Reputation: 664

Post » Sat Feb 09, 2013 8:33 am

@briermay You don't need to mess around with UIDs or IIDs for this purpose. Construct will always use the instance of an object that is picked by the condition of an event. See How events work in the manual. The picked instance also extends to sub-events for further filtering. See Sub-events in the manual.

For beginners, as long as you have your action in the same event as your condition, you can freely call the object as a whole and it'll use only the instance that triggered the event.

Example capx [R118].GeometriX2013-02-09 08:37:51
B
56
S
15
G
10
Posts: 910
Reputation: 11,972

Post » Sat Feb 09, 2013 8:56 am

[QUOTE=Cowdozer]I watched your Plugin tutorial and it was a nice intro. :) Construct 2 seems very easy to extend that way![/QUOTE]
@Cowdozer
Thanks! Yes, C2's extensibility through plugins is one of its attractive features. I haven't used a regex in any of my plugins, though - yet ;)

@briermay
Another of C2's attractive features is the way in which, as GeometriX says, it will always use the instance of an object that is picked by the condition of an event - without any more work on your part. (Don't be misled by the earlier discussion in this thread, which revolved around a rather esoteric problem.)
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 27 guests