How do I click a set of buttons based on a json data?

0 favourites
  • 7 posts
From the Asset Store
High quality sound effect pack, in the following categories: Simple, negative, pozitive
  • Hi, I have a 3 sets of buttons (btn1, btn2, btn3) and when you click on each, it plays a different sound. Now I am trying to find a way when I click a different button like play button, this would read an array or Jason file with data like [1],[3],[2] meaning it will auto click btn1, followed by btn3, and btn2.

    Any guide would be appreciated.

  • So far I created a global variable called ButtonClicked

    Then I created a func called OnButtonClicked and added sub events as seen below

    https://snipboard.io/hAq8fg.jpg

    Now I have a play button which when I click, I want to be able to play the sequence but how do i pass the sequence data to the function?

    https://snipboard.io/pxhLvl.jpg

  • It's better to change ButtonClicked variable to function parameter, then to play a sequence you simply call this function multiple times with different parameters:

    Call OnButtonClicked(3)

    Call OnButtonClicked(1)

    Call OnButtonClicked(2)

    etc.

    If you have this sequence in an array or JSON, you need to loop through the values and call this function in the loop.

  • How do you set the value in the call function as suggested

    Call OnButtonClicked(X)

    Call OnButtonClicked(Y)

    Call OnButtonClicked(Z)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You need to add a parameter to your function. Right click and select "New parameter" or press P on keyboard.

    Parameters in functions work like variables, but you can set them directly in function calls.

  • Yes I know that but feeding the values is where I could not understand. What I have just done now is this as a test:

    Set Array object values as follows: Width = 1, Height = 1, Depth = 3

    On start of layout: set array value at 0 to "2,1,3"

    So in debug mode you see this in array: Data 0 = 2,1,3,0,0

    When I click the button, it only plays the value 2 and ignores the rest values.

    So it looks like doing "2,1,3" is seen as one value rather than 3 separate values.

    How do i insert more than 1 value in the array so it should look like 2,1,3 rather than 2,1,3,0,0

  • You need to set array size to width=3, height=1, depth=1

    If this doesn't fix your issue, please post your project file or a screenshot of events.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)