Velojet's Recent Forum Activity

  • Weishaupt: Arima's words are very wise. Frustration comes with the software development territory. We welcome the frustrating challenges for their intellectual stimulation and for the motivation they provide to develop better software.

    Let your frustration drive you to isolate this bug and then be able to say for certain whether it's in your code or in the Construct 2 engine. Until you do that, it's premature (and yes, unreasonable) to ask the Scirra developers to help in your hunt.

    Use the excellent debugging advice that Ashley and Arima have given you. Effective debugging strategies are a vital part of the toolbox of any software developer.

    Happy hunting!

  • 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:

    var instance = new ObjectType();
    ...
    instance.favorite = true;

    ... 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.

  • Kyatric, Yann: Thanks immensely for so patiently and promptly sharing your knowledge! You've helped to clarify a number of issues concerning object instances.

    So what have I learnt? (Please tell me if I've got any of these conclusions wrong!):

    In order for an event that's dependent on a system condition to affect only a particular object instance that's chosen in advance by the coder at build time, we need to have some means of picking that instance (other conditions can be filtered for particular instances as explained in the Manual). Such system conditions can occur when a game is replayed, or a new level is reached, or a certain time has passed, and we then need to reset the state of a particular instance (e.g. the centre cat in our demo).

    Construct 2 offers no way of naming individual object instances at build time (unlike OO languages). (It might be thought that UIDs could be directly used for this purpose, but their value is not known till runtime, so can't be used when building). There are workarounds to ensure that such a system condition will affect only a particular instance:

    • One workaround is to set up an event to save the (runtime) value of an instance UID in a global variable, and then use that variable to pick that particular instance.
    • Another workaround is to add to an object type an instance variable that can be given a different value for each instance, and then be used to pick a particular instance. This is what we all seem to be agreed on, since each of our demos has the same 'Reset' event:

    <img src="http://www.millercrawford.com/images-offsite/construct2/reset.png" border="0" />

    Again, please tell me if this doesn't make sense - or if there's some simpler way of doing this!

  • Thanks again, Kyatric and Yann. Shock bis wins on conciseness!

    At first glance though, it does indeed look as though each cat requires that additional Boolean instance variable that I gave it ('colour' in this example) so that, when resetting, it can be used to pick the centre cat and set its 'favourite' Boolean to 'true' (having reset all the others to 'false').

    Out on another job now, however, so I'll study your demos more carefully tonight and come back with further comments.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here're a couple of demos of my own. First, a reminder of what I'd like to do:

    To have a means of identifying each particular cat at the point of placing them on the layout.

    I can do that in JavaScript (or any OO language) by giving each a unique instance name e.g. 'centreCat'.

    I can't see any way of doing that in Construct 2. That's why I call any way of achieving the same outcome a 'workaround'.

    This capx shows one workaround (following suggestions by Kyatric and Yann) - and one example of why I need to have a means of identifying a particular cat at the point of placing it on the layout. (Thanks again to Kyatric for his graphical interpretation of my verbal description!)

    When the game is reset (e.g. when the game is over and we want to play it again), I need to revert to making the centre cat (black) the favourite, by setting its 'favourite' Boolean instance variable to 'true'.

    Hence my need to be able to identify that cat at the point of placing it on the layout. And hence this workaround:

    Give each cat an additional Boolean instance variable: 'colour'. When resetting, use the 'colour' Boolean to pick the centre cat and set its 'favourite' Boolean to 'true' (having reset all the others to 'false').

    This capx shows another workaround (following suggestions by Ashley and Yann): At the outset, I save the centre cat's UID in a global variable 'CentreCatFavourite'. When resetting, I pick that cat instance with its UID and set its 'favourite' Boolean to 'true'.

    Thanks again for bearing with me!

  • Kyatric Lovely work ! Mille remerciements !

    I'm going to have a close look at your demo later today (8:20am here in NZ, and I have to go out on a job now).

    Your demo capx gives me a much better way of explaining my query and then going on to look at possible solutions (including yours, of course).

    I really appreciate the attention and effort you're giving to this issue.

  • Thanks for bearing with me, folks!

    I take it from what you say is that there's no way in Construct 2 of directly doing what I can do in JavaScript with " 'centreCat.favorite = true' ".

    And now that I've confirmed (I think!) that there's no direct and simple way of doing this that I've missed, I'll work on giving a fuller example, together with what seem to me to be the workarounds that you've suggested.

    I'll be back and hope you can bear with me a bit longer :)

  • Kyatric "Compare the value of an instance variable that you set in the IDE".

    Thanks, I'm aware that you can do it by comparing instance variables, but that seems to me to be a roundabout way of identifying a particular instance in a system condition.

    I was hoping that there's some more direct way of knowing the IID of each instance and being able to use that.

    For example, let's say my layout has a cat in each corner and a cat in the centre. Is there any way I can tell what the IID is of the cat in the centre?

    In JavaScript, they'd each have different names (e.g. centreCat, topLeftCat, ...) and I could say 'centreCat.favorite = true' (with all the cornerCats having their 'favorite' Boolean set to 'false').

    So another way of asking my question is:

    How do I program 'centreCat.favorite = true' in Construct 2?

  • Kyatric Thanks for your rapid response!

    ... but I want to get the system to pick a particular Cat instance (say, the black one), not a random instance. How do I do that? How do I know what IID the black cat has?

  • Yann thanks for the instant reply!

    I can see that that would work when there's user interaction with the cats. But what if there's no user interaction and it's the system that's doing the selection?

    For instance (!), if Cat objects have a Boolean 'favorite' instance variable that's set by the system for one particular cat when a new level is reached, or the game is replayed, or a certain time has passed, how can I add a condition that targets that Cat instance (and that alone) ?

  • If I've placed 5 objects (say, of Object type 'Cat') on a layer, how can I know which Cat has which IID? Or to put it another way, if I pick Cat instance 1, how do I know which Cat I'm picking?

    The IID for a particular Cat instance is not shown in the Properties Bar (because the IID is allocated at runtime?), so how can I pick it with certainty when I add a condition that will target an action on that Cat instance alone?

  • Many thanks, Tom. Frustration vanished!

Velojet's avatar

Velojet

Member since 22 Nov, 2011

Twitter
Velojet has 1 followers

Trophy Case

  • 13-Year Club
  • x3
    Coach One of your tutorials has over 1,000 readers
  • x2
    Educator One of your tutorials has over 10,000 readers
  • Email Verified

Progress

16/44
How to earn trophies