99Instances2Go's Forum Posts

  • Same in both: Sprite.8Direction.MovingAngle.

  • Solution:

    I've sent the UID of all the objects from the family in a array and then I create an event "Pick instance with UID - UID number from the array" from the family.

    It worked perfectly!

    Sure, that somehow works. And next ?

    Are you going to write 4000 events to follow that up? Like ....

    1/ If this .... then pick UID this ... and do this ...

    2/ If that .... then pick UID that ... and do that ....

    3 to 4000/ If something else .. then pick UID something ... and do something else ....

    Should explain what exactly you wanna do.

    At this point i am afraid that you gonna create a vehicle that will overshoot the moon.

  • Use a function.

    Add Function object.

    Add a separate block of events that starts with 'On function', here goes all the stuff that you want the function to do. I will refer to this as the function block.

    Say we name it "CompareSymbol"

    Function > On function ... Name = "CompareSymbol"

    ____Local variable 'Symbol' <---- not needed, but it is easier for the eyes.

    ____Empty sub event

    __________ action: System > Set value .. Symbol to Function.Param(0) <--- i explain this later

    ____if array at position 0,0 = symbol < --- the local variable

    ____if array at position 1,0 = symbol

    ____if array at position 2,0 = symbol

    __________ action: Function > Set return value ... value = 1

    ____else

    __________ action: Function > Set return value ... value = 0

    Now you have this block only once. And you can call it as many times as you want.

    This action 'Function > Set return value' sets a special system variable. You can access it with an expression.

    The value is there and has meaning direct after calling the function.

    So, lets call the function.

    Any condition that leads to comparing the Symbols.

    ____ Action: Function > Call function .. Name = same as in the 'On function'. In this case "CompareSymbol" .. parameter 0 = "symbol_02"

    ____ Sub event: System > Compare 2 values .. First = Function.ReturnValue .. equal to .. second = 1

    __________actions: do the needed stuff when the array is matching the symbols

    ____ Else

    __________actions: do the needed stuff when the array is NOT matching the symbols

    With the expression 'Function.ReturnValue' you access the value that you have set with that action 'Function > Set return value ... value = 1' in the function block.

    Now. When you call a function, you often have to pass values to the function block. Those are called the parameters. In this example, the function needs the value 'symbol'. We have set 'symbol' to Function.Param(0) in the function block. What is this ?

    When you click the action Function > Call function ... you see that 'Add parameter' line in the UI. Click it to add a parameter. A new field appears to fill in a parameter with in index zero.

    In that field you type the symbol that you want to call the function with. "symbol_01" or "symbol_02" .......

    It is in fact always the same.

    When you set a value in an action, there is (almost always) an expression to access that value.

    Action : On function'... name ="CompareSymbol" .. parameter 0 = "symbol_02"

    Access that parameter with Function.Param(0)

    Action : Function > Set return value ... value = 1

    Access that return value with Function.ReturnValue

    Same as the more common

    Action: Sprite > Set X ... X = 150

    Access that X with Sprite.X

  • But now i only checked only 1 frame. Guess i need to check a range of frames.

    Using an Array (size : how many frames , 1 , 1)

    An Array is just and no more then a way to organize variables that can have more values at the same time.

    System > For .. Name = "aFrame" ... Start = zero ... End = how many frames

    Sprite > Compare frame ... frame = loopindex("aFrame") ?

    _____Sub / System > compare 2 values .. Sprite.Count = Sprite.PickedCount

    ___________Sub / Array > Compare at X .... X = loopindex("aFrame") ... Value =? zero

    _________________sub / System > Pick All (Sprite)

    _______________________action : do your stuff

    ___________Sub / Empty event

    _________________action : Set at X ... X = loopindex("aFrame") ... Value = 1

    _____Else

    __________action : set Set at X ... X = loopindex("aFrame") ... Value = 0

    Else

    _____ if it is needed to capture the exeption

  • Use a sub-sub or a function.

    A function starts picking from scratch. (so, including ever instance again)

    A sub-sub will not change the parent picklist.

    Sprite > Compare frame <--- pick all with a certain frame = Parent Picklist

    System > compare 2 values .. Sprite.Count = Sprite.PickedCount

    ______Just an empty sub event

    ________sub under that empty event ... System > Pick All (Sprite) <------ this is the Sub Picklist / Parent is unchanged when returning to parent level

    ______________action : do your stuff

    Thing is now, be careful with this 'PickedCount'. If you wanna do something when none of them have this frame .... Then the 'Sprite.Count = Sprite.PickedCount' will not ever run. Not as sub, not as second in a parent.

    So just to be complete ...

    Sprite > Compare frame

    System > compare 2 values .. Sprite.Count = Sprite.PickedCount

    ______Just an empty sub event

    ________sub under that empty event ... System > Pick All (Sprite)

    ______________action : do your stuff

    Else

    _____Actions to take care of the exception where the first event will not run.

    Additional. Testing for an animation frame has a dangerous side.

    Say, the animation speed = 20 and it runs at 60 FPS. Then each frame will be there for 3 ticks. (when the animations sync up)

    As a result this condition (above) will be true for 3 ticks in a row.

    Usually you solve this with a 'System > Trigger once while true'.

    Sprite > Compare frame

    System > compare 2 values .. Sprite.Count = Sprite.PickedCount

    System > Trigger once while true

    'Trigger once while true' runs its event once when the paired up condition(s) are true. Then it sits there, and waits. Until the conditions are not true, then it flags its event as executable again.

    But that will not be flawless in the above conditions because of the above explained exception.

    When there i no Sprite with that frame, the condition will not run, the 'Trigger once while true' will also not run.

    As a result it miss out the change in true/untrue for the next tick.

    There is also the possibility of an additional 'thing'. Say, the animations do not run in sync. Then 'this tick' a certain sprite changed frame, while another one is still in the same frame.

    Comes down to this. When Sprite.Count is equal to Sprite.PickedCount this tick it can only run its actions when Sprite.Count was not equal to Sprite.PickedCount in the previous tick.

    Using a Global Variable.

    Sprite > Compare frame

    _____Sub / System > compare 2 values .. Sprite.Count = Sprite.PickedCount

    ___________Sub / GlobalVariable = zero ?

    _________________sub / System > Pick All (Sprite)

    _______________________action : do your stuff

    ___________Sub / Empty event

    _________________action : set GlobalVariable to 1

    _____Else

    __________action : set GlobalVariable to 0

    Else

    _____ if it is needed to capture the exeption

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • MikaelS

    That sounds about right. Cant set them to an expression in the current version of c3.

    That hit me too.

    Got to couple them to a condition.

    Condition ... testing an expression

    _____ set boolean

    Else

    ______unset boolean.

    Got to be careful with the logical part of that condition. The 'else' runs only if its parent did not run. (is false)

    Those conditions that start with 'Is ....' are conditions that return a 'false/true' as result.

    The conditions that pick return a 'false/true' if the picklist is empty.

    Those that start with 'On ....' have no 'else', they are triggers.

    Whats left, is those that start with 'Compare .....'.

    You can compare in two ways.

    Say ...

    Regular way. Comparing two expressions that hold a value (Sprite.x ... 5000 .. pi ... sin(90) ...etc)

    And...

    Using logical expressions.

    Value one = Sprite.x > 50 & Sprite.x < 200

    Value two = 1

    Construct takes '0' as false when using logical expressions. And '1' as true.

    You can also use logical expressions like this.

    Sprite.X = 1? 1 : 0

    Returns 1 if Sprite.X = 1 else 0.

  • Not sure why so complicated. Or use drag&drop or use an boolean together with a position to mouse (every tick).

    If you use drag&drop, it does not need to be disabled. Unless the buildings have a state that does not allow them to move. But i dont see that in your events.

    Now you have all the drag&drop conditions.

    On drag start

    ___ Here you can set the boolean, if you need it

    On drop

    ___ Here you can unset the boolean

    ___ Reposition (snap) if need

  • Set elasticity to zero. More damping. And a density to like 6 or so (so they are weight more compared to your object).

  • An old example.

    Same with spawning in the other order.

    https://www.dropbox.com/s/xupduervio26y ... .capx?dl=0

  • LOS has a range.

  • Still, what randomly said is right. You just have to turn around the logic.

    Use line of sight on an object that sits on the light sources. When it see's an enemy (whit the shadow casting objects as obstacles) set a boolean in that enemy.

    Has LOS to object picks that object.

  • If you talk about 'link' then there are 2 sides to it.

    Link (1) as in "when one moves, the other moves with it".

    &

    Link (2) as in "when one gets picked, the other needs to be in the picklist too"

    For (1) you can use the behavior 'Pin'. Use 1 sprite as the base for the others. Pin the others to it.

    Before pinning, they have to be in position. Since you have carefully crafted them in the layout, that should be not prob.

    You dont have to use 'Pin', you can also set the position of one to image points of another one EVERY tick. To do this, you need to be able to properly pick them. And that brings us by link (2).

    For (2) You can pick based on an instance variable. Give them all the same named instance variable. Say 'ID'. Now in the layout change that variable, for those that belong to each other, to the same value.

    Now when ever you pick one, you can pick the other that belongs to it.

    Example:

    Mouse > On object clicked (button) <------- this picks the button that is clicked on

    System > Pick by comparisation > object = text .. expression = text.ID .. value = button.ID <---- this adds the object text with the same ID as the button to the picklist

    System > Pick by comparisation > object = indicator.. expression = indicator.ID .. value = button.ID <---- this adds the object indicator with the same ID as the button to the picklist

    ............... and so on, for all objects ....

    ... Actions work on the picked objects only.

    So you can after a pick like do in the actions ...

    (object) text > action > Set position to another object ... object = button .. and use that imagepoint

    (object) indicator > action > Set position to another object ... object = button .. use that imagepoint

    For (2) you can also use a Container. Look them up in the manual. They are extremely handy. But not for you in this case. Since you have everything set up in the layout. Containers help by creating and linking objects during run time. And they expand the idea about linking.

    They ...

    link (1) If one gets picked, the other gets picked.

    link (2) if one gets destroyed, the other gets destroyed

    link (3) if one gets created, the other gets created

    To finish, lets break down button.ID above.

    We call this an expression. If you look in the online manual. You always see 'properties', 'conditions', 'actions' and 'expressions' explained.

    An expression is info about an object (and optional its behaviors). They are always written the same way.

    button.ID

    button = name of an object.

    the dot = kinda a separator

    ID is the expression, in this case the expression for the instance variable 'ID'.

    Another example.

    Sprite.Angle

    Sprite = name

    the dot

    Angle = angle for the Sprite

  • I have should have seen that it is a variable.

    Still dont understand the flow.

    But.

    Is this helping ?

    https://www.dropbox.com/s/q8ba5y0ukogr5 ... .capx?dl=0