Geoffroymonde's Recent Forum Activity

  • Hello everyone !

    I'm trying to automate a particular behaviour of buttons being created at runtime.

    When the player clicks on a sprite ("Sprite1"), a serie of new smaller sprites ("Sprite2") should appear all around Sprite1.

    Every Sprite2 is visually linked to Sprite1 with a solid white line.

    In the end, the Sprite 2 should look like the rays of a sun, evenly distributed all around Sprite1, regardless of their number (for example, if 4 Sprite2 are created, they would each go in a different direction at 90°, but if there are 6 Sprite2, they would each be at 360/6° all around Sprite1, etc.)

    Then, once every SPrite 2 has appeared, they will each spawn another sprite ("Sprite3") on their center - but each one of those Sprite3 is different (but has to be distributed in the right order) - I have a hunch using families will be useful for that one...

    Here is the code I wrote for the spawn animation of Sprite 2 (composed of a line and a square) ; the sprite named "subbut_mouth01" corresponds to a Sprite3) ; to summerize : when the player clicks on a button, a white line is created on the originPoint of the button ; that line is created at 0 height, and goes to a 150px height with a lerp ; once that height is achieved, a white square is also created on the top origin point of the white line, and then, once the square is at the right dimensions, the Sprite3 appears in the square)

    And here is a quick sketch of what I'm trying to achieve :

    What I'm having difficulties with is :

    - automate the creation of Sprite2 with only a simple parameter (the number of instances to create) to adjust, with that parameter being also linked to the angle at which every new sprite2 should be created

    - specify in the code which sprite3 should go with which sprite2 (I'd like that to be "automatic", as long as there are the same number of sprite2 that appear as there are sprite3 needed to display.

    Thanks in advance for tour help and tips !

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Okaaayy ! I didnt know the mere hierarchy of the orders was enough for something like this to be consistent !

    Thank you very much, I'll try this !

  • If you create a sprite called blueSprite, you can load its UID into variable whoAmI with

    whoAmI=blueSprite.uid.

    If you want to use that specific sprite again later you can get it with

    pick blueSprite by UID whoAmI.

    I hope this helps.

    yours

    winkr7

    Hye !

    Thanks for the walkthrough.

    Would it work the same if there are 4 instances created at the same time ? How would the variable identify which is which ?

  • Yeah you can pick them out with different instance variable values if they do different things. Depends what exactly they are used for. If you want to display text you can set the text in an instance variable on the object itself and say on object clicked > display text object.text

    Yes ! That's actually what my question was about originally : HOW does one set up instance variables so that we can identify each one at runtime ? R0J0hound's solution took me closer to my goal and might be the solution I was looking for, but it created new problems also.

    So I'm looking for an example of how would one simply get an instance's UID when it's created, and use it afterward (preferrably by using an instance variable).

    When an instance is created, how to know its UID in runtime ? And how to use that information again in the code (how to keep it in memory, and point to it later, for example) ?

    (about your example about text : I actually use the function properties to inform the text on text object created, which in turn points to an array's coordinate, where all my text is. But I would still be curious as to how you would set that example with text up, since it might answer my more general question !)

  • > I see ; I will try what you propose ! R0J0hound.

    >

    > lionz

    > My understanding is, "On object clicked" should be accompagnied with another condition that specify WHICH instance was clicked, isn't it ? Because each instance has a specific causal effect, so the rest of the code must evolve accordingly to which specific instance was clicked.

    > Am I being clear ?

    Nope it just picks the one that was clicked. The actions next to it only apply to that one instance.

    I'm not sure I follow (sorry if I'm being dense XD)

    In that scenario :

    Create object "Sprite 1"

    Create another instance of Sprite 1 (but with different X,Y attributes given by the function's parameter)

    Create another instance of Sprite 1(but with different X,Y attributes given by the function's parameter)

    Create another instance of Sprite 1(but with different X,Y attributes given by the function's parameter)

    On Sprite 1 clicked => do action

    Every instance of sprite 1 created has to have a different consequence.

    It seems to me that only having as a condition "on object clicked" (here, "sprite 1" being the specified object) will not automatically inform the game which action to follow up with.

    I'm looking for a way to inform, in the code, what happens when a particular instance is clicked - where to go from there.

    In my experience, it doesn't work on its own. I tried the solution of having a instance variable (attached to the "sprite 1" object) evolve according to the instance clicked, and it does work, once coupled with "on object clicked".

  • [

    R0J0hound

    After messing with your idea a little more... It looks like it's working !!

    Here is the function (and the setting up of the var according to the position of each instance, line 34 & 35) :

    And here is the code for the "on object clicked" :

    It looks like it's working for now ! I will go a little deeper with it and see if it holds.

    Thank you for your time !

  • Looks like you’re creating the four objects in specific locations. You could compare the x and y to pick specific ones. You could give the object an instance variable and set the variable to something unique when you create it.

    Start of layout
    — create sprite at 100,100
    — sprite: set var to “left”
    — create sprite at 200,100
    — sprite: set var to “right”
    
    On clicked on sprite
    — sprite: var= “left”
    — — do something
    — sprite: var= “right”
    — — do something else

    Okay, after thinking about it, I don't think it's that simple, but maybe I'm missing something.

    Remember I'm creating an object (a sprite) two times, but everytime, it's a different instance of the same object.

    So the var will always be set to what the last instance created will have set as a var.

    Like, in this example where 3 instances of a unique sprite is created :

    create Sprite 1

    set var=1

    create Sprite 2

    set var=2

    create Sprite 3

    set var = 3

    In the end, the var will always be "3", right ?

    So whichever sprite I click on, the var being set on 3, it will always lead to whatever is programmed to happen when var=3

    And I would love to be able to use the position (which is a function parameter, named "position", that specify the position of the instance created) but I cannot use a function's parameter as a condition. I cannot add as a condition to "on object clicked", something like "pick the instance which parameter is position = XX".

    I do understand the answer lies in using an instance variable, it really seems to be the easiest way to go about it, but I still don't understand how to set this properly.

  • I see ; I will try what you propose ! R0J0hound.

    lionz

    My understanding is, "On object clicked" should be accompagnied with another condition that specify WHICH instance was clicked, isn't it ? Because each instance has a specific causal effect, so the rest of the code must evolve accordingly to which specific instance was clicked.

    Am I being clear ?

  • For example, lionz, I actually came across a forum board where you said the following to a user :

    You have to do something a little extra for this, you would store the instance selected, for example the UID, in a local variable with your 'on selected' event. Then as a sub event you 'pick all' instances and set opacity 100, then again as a sub event you pick the instance by UID, the variable value you stored, and set it to 70.

    This is because when you use on selected event it narrows the selected instances to just 1, you have to open them up again with pick all to set everything back to default, then return to the original one instance to pick that and set it to 70. Hopefully that makes sense.

    I believe this is exactly what I need to be able to do ; but I don't know how to actually proceed to achieve the emphasized part !

  • If it is based on which one the player clicks, you can use the condition 'on object clicked' under the Mouse object conditions.

    Hye !

    yes, I know about that condition ; my main problem is to identify WHICH object is clicked, since there's only one object, but many instances of it. Each instance should not have the same result ; hence my need to be able to identify every instance individually on runtime.

  • Thanks ! I actually just needed to use a "for each" , which I use a lot throughout my project, but for some reason forgetted about in this specific case...

  • I know my question is pretty basic, but for the life of me, I can't find any tutorial that explains clearly what I'm looking for, even though it seems it's quite a basic thing to set up ! Lots of forum message boards saying "just create an instance variable to keep track of the UID of instances created" without any more details, and that isn't very helpful to me...

    Here is a more detailed breakdown of my problem :

    I'd like to be able to differentiate, on runtime, between 4 different instances of an object created at runtime. So that when one of those is selected, the code knows which one was selected and acts accordingly.

    To be more specific :

    Here is the function that is called : it creates a button that gives the player a dialogue choice (and the parameters allow me to specify the position of each button as well as their text input) :

    Then in the event, I'm calling this function as many times as I need dialogue options for the player (here, 2 options) :

    But I can't then have the rest of the code follow accordingly to what button the played clicked, since I don't know how to pick those dynamicaly.

    I tried a lot of things with UID and all, but I must be doing it wrong since it never works (plus every tutorial I come across isn't tailored to my needs obviously, so it never works when I'm trying to translate it to my project).

    You can discard the crossed out section of the code, which is precisely one of my attempts, with an instance variable on the button object, to keep track of the instances' UID (it failed).

    Thanks in advance for your help !!

Geoffroymonde's avatar

Geoffroymonde

Member since 13 Jan, 2024

None one is following Geoffroymonde yet!

Trophy Case

  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • Email Verified

Progress

3/44
How to earn trophies