CannedEssence's Forum Posts

  • Can you share the event/actions in question?

    It's probably that you aren't providing the object as the context of the action, and rather you are just referencing the position in the action's instruction (on the right side of the action).

    I'm guessing your action looks something like this:

    System -> YourObject.X [do something]

    This will reference just the first object in the list of instances of YourObject.

    You'll either have to do something like this:

    YourObject -> self.X [do something]

    or

    Event: System -> foreach YourObject

    Action: System -> YourObject.X [do something]

    Good luck!

  • Thank you for all your responses =), especially ramones-- you look like you put a lot of effort into that answer. I'm glad to join such a helpful community.

    I think I see the pattern now. I'd be grateful if anyone can confirm the truth about the following assumptions concerning the behavior of Construct 2 Events.

    Quick definitions: "context of action" refers to left side of action statement; "instruction" refers to right side of action statement.

    • The context of the action (e.g. "Ball") will reference all the instances filtered (or "picked") from the condition(s) of the event (generating a "selected object list"), or simply all existing instances of the object type if not referenced in the condition(s).
    • An arrayMap of the instruction will be applied to the context.
    • If the instruction references the context object (or more accurately the SOL for the context object type), then the properties (instance variables) for the instance of the object in the instruction will line up with each object in the SOL when the instruction is performed on each instance in the SOL.
    • If the instruction references an object type that doesn't match up with the context, then the properties of that object will reference only the first object in the all-existing-objects list for that type, or SOL if that object type was referenced in the condition(s) of the event.
    • For static classes like "Function" or "System" as the context, there is only one instance, so the instruction will only perform once no matter what, unless you use a foreach condition.
    • If more than one object type is referenced in the conditions for the event, then a separate SOL will be generated for each object type.
    • Using a foreach condition will override the default arrayMap behavior of the context object. See image below:

    <img src="http://cannedessence.com/public_images/impliedForEach2.png" border="0" />

    Note that the ball action would ordinarily arrayMap the instruction (or create a for each in this code translation), but here if we add a foreach condition, it overrides that and instead the context becomes just the current instance of the context object in the outer foreach loop.

    Is this all correct?

    If it is, then I hope that other people in the future see this thread, because I had trouble finding these clarifications elsewhere. The foreach and SOL part of the manual is a bit scant, but I guess I understand, since it's probably a bit advanced for the target user of the tools.

    Thanks again!

  • It does pick all, but like you said it passes only single value to function as it is just single variable. Put for each sprite loop at the condition where you call the function. This will call the function for each picked sprite.

    Thank you, I feared it would have to resort to something like that.

    When an event picks more than one instance of an object, don't the actions work like a foreach loop themselves?

    For instance, say there's a game where there are balls, and some of them are spiky, and you want to move all of the spiky balls one pixel to the right.

    Construct 2 logic:

    Event: Ball -> Is isSpikey

    Action: Ball -> Set X to self.X + 1

    loose programming translation:

    foreach (Ball ball in listOfBalls)

    if (ball.isSpiky)

    ball.X += 1;

    ----------

    Doing this with functions:

    Construct 2 logic:

    Event: Ball -> Is isSpikey

    Action: Function -> Call "MoveOnePixelRight" (Ball.UID)

    Event: Function -> On "MoveOnePixelRight"

    Sub-Event: Ball -> Pick instance UID Function.Param(0)

    Action: Ball -> Set X to self.X + 1

    loose programming translation:

    foreach (Ball ball in listOfBalls)

    if (ball.isSpiky)

    MoveOnePixelRight(ball);

    void MoveOnePixelRight(Ball ball)

    { ball.X += 1; }

    ---------

    Do you see how this makes sense?

    I don't see why I have to add a foreach to Construct 2 when it appears that that's what the event logic is doing by default.

    Why is this:

    Event: Ball -> Is isSpiky

    Any different than

    Event: Ball -> Is isSpiky

    Sub-Event: System -> For each Ball

    ?

    Thanks for the help =)

  • If you see "green arrow" in condition field it would fire once time. Use global variable or method do not have green arrow, it would do action in every tick.

    Thanks for the suggestion. However, as I said in my previous reply, it's not the event condition that's keeping the function from firing for each instance of the "Sprite" object. For example, look here:

    <img src="http://cannedessence.com/public_images/functionIssue2.jpg" border="0" />

    Notice how I got rid of the "green arrow" trigger condition. However, if you try this out in the capx, you'll see that it is still only calling the function once per tick, passing only the first instance.

    Once again, if I did not have that function call, it would perform the action for the whole batch. It is entirely related to the function call from what I can tell, but I don't know why.

  • Hi, I'm having some difficulty understanding what you're trying to achieve here, but it looks like the function will only run once because you have it set to on mouse click. If you wanted it to keep running you would need to set up a variable and if it was true then run the function every tick, if it was false stop the function.

    The hasMoved variable is an instance variable, so the event should pick all objects with their hasMoved set to true. If you uncomment the disabled action, you'll see that it does in fact successfully do that.

    This generic project is designed to isolate the function call as the problem. If I hadn't used that onrightclick trigger, but a different means of picking all the objects, it would do the same it is doing now.

    So it appears that it is picking all the objects, but only calling the function once, passing the first object's uid.

  • CAPX: iu.box.com/s/kkldjgprvbys5hk97fs1

    I've created this sample to isolate a problem.

    Essentially, when more than one objects are picked in an event, and I try call a function with the UID as the argument, it seems to only call the function once.

    Thanks, any help would be appreciated.

    UPDATE: Added image below in case you can't see CAPX

    <img src="http://cannedessence.com/public_images/functionIssue.jpg" border="0" />

  • Whats wrong with a function, and/or a wait?

    So, you're suggesting with a function I would do:

    Event: Buttmode == True

    etc conditions...

    Main Event Actions:   CheckForExtraButt()

                          ButtPoints += 10

                          ButtMode = False

                          ExtraButt = False

    Function ExtraButt()

        Event: ExtraButt == True

          Actions: ButtPoints += 1000

    Is that correct?

    With that workflow I would have a separate function for each simple if condition I needed to check before the other actions.

    Not sure what you mean by a "wait". Are you saying to add to the main event's conditions a wait .5 seconds or something? So that the sub-event gets asynchronously checked?

    Thanks for all the tips

  • Hmm... I guess an empty sub-event would do the trick... I'm just getting into this, and somehow I'm kind of scared of the "tricks" I'm going to have to do.

    Thanks for the suggestion!

  • Sorry, let me revise my original example. I got carried away with the butts. Add an action to main events where ExtraButt is also assigned to false

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi, I couldn't find the answer by searching.

    I'd like to make my sub-event trigger immediately after the event fires, then do then perform the main event actions.

    For example:

    Preferred:

    Event: Buttmode == True

    etc conditions...

    Sub-Event: ExtraButt == True

        Sub-Event Actions: ButtPoints += 1000

    Main Event Actions: ButtPoints += 10

                          ButtMode = False

                          ExtraButt = False

    How it is now:

    Event: Buttmode == True

    etc conditions...

    Main Event Actions: ButtPoints += 10

                          ButtMode = False

                          ExtraButt = False

    Sub-Event: ExtraButt == True

        Sub-Event Actions: ButtPoints += 1000

    If main event actions fire first, then the sub-event won't fire because ButtMode is assigned to false. How do I move the sub-event up before the main event actions?

    Thanks!