Array as a function parameter

0 favourites
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I made the function: speakArrWithDucking.

    The function has one parameter: arrToSpeak.

    In this parameter I want to pass the array.

    My array will be built with text and number pairs one after another:

    "text 1", value in seconds, "text 2", another value in seconds, etc.

    In the function I will use a speech synthesis for the text, then wait for the number of seconds and so until the end of the array.

    To determine the array size I want to use:


    because I found a description in the documentation Width: Return the size of each of the array's dimensions.

    But the system does not accept such a command. I have a message: Not an object.

    Is there any way that I can specify the length of the array in the parameter?

  • The term array is a bit misleading since you are using a function string parameter.

    The variable has no derived methods that you can access, unlike objects, so variable.width doesn't work here.

    However, assuming you have a delimiter , e.g. "," you can access parts of the string and parse them.

    tokencount(arrToSpeak,",") will get you the count of elements

    Since in your case they go in pairs, the amount of "array" elements is tokencount(arrToSpeak,",")/2+1

    To access a certain element inside the string, you can use tokenat(arrToSpeak,index,","), so tokenat(arrToSpeak,0,",") will get you the first text, tokenat(arrToSpeak,1,",") will get you the first value in seconds, and so on.

  • Thanks thanks thanks!

    This is a very big thank you, because I am very grateful for any help.

    I have learned a lot already, but I still meet the high walls, which I hope someone will show me how to beat.

    I could not test it, I was stuck on picking up the array as a parameter.

    First, I will describe the case with the array, but it seems to me that a better solution will be if I store data in instant variables.

    1. Array as parameter

    I want to call the speakArrWithDucking function and give my array as a parameter.

    At this point, Construct displays:

    '11_full_desc' needs an expression after it.

    This is an object name so you need a dot and an expression name after it.

    I looked through the possibilities following the dot, but I found nothing suitable.

    You wrote:

    The term array is a bit misleading since you are using a function string parameter.

    But I would like something other than a string as parameter, more specifically, I would like an object :-)

    But the object can not be selected while creating a function parameter.

    I chose the String because there is also Number and Boolean to choose from the list. So it seemed reasonable for me.

    2. Instant Variables

    I thought that a simpler solution would be to pass a string of texts and numbers in the Instance Variables.

    The reason for such thinking is the fact the array is more work when it comes to filling them on start the game.

    So I created an instance variable called short_desc.

    There, I put the test data.

    But after many combinations, I did not find out how to refer to this by calling the function.

    There is very little information about the Instance Variables in the documentation:

    I tried, among others, like this:




    but nothing works, can I ask for a suggestion?

    Maybe there is some documentation about these types of queries?

  • Explain as simply as possible what you are trying to do with the function because this isn't making much sense The original explanation given is too vague and doesn't really say what you are trying to do. You're trying to pass an array object through a function? It will be possible to achieve what you want to do but I cannot work it out from the information given.

  • You're trying to pass an array object through a function?

    Yes Plinkie, I'm trying!

    but Yoda said there is no try ;-)))

    and more seriously writing I would like to know how to do it. I will probably use this in several places of my code.

    However, the second and most important thing is to call a function with a parameter.

    In this parameter I will pass the selected Instant Variables of the selected object.

    For example, this ugly piece is trying to get this parameter works:


    where short_desc is instant variable of object room with UID 11.

  • Like plinkie said, at this point it might be the best if you share a sample c3p file and describe what you want to achieve, we then figure out the best way to do it.

    In short, there are objects of type array and dictionary that you can use, or a JSON string. But we need to understand your goal first.

  • For example, this ugly piece is trying to get this parameter works:


    where short_desc is instant variable of object room with UID 11.

    Then you send through the UID and short_desc variable through the function as parameters, and on the function end you pick the room by UID with param, and set text to param short_desc or whatever you plan to do with that.

  • The shortest way may be to pass the room UID as function parameter.

    Then inside the function, select according the UID. This way you can access the object's variables inside the function without the need of passing it's variables as separate parameters.

  • Thanks! It's almost perfect :)

    1. I take the ID of the object with which the player has a collision.

    2. I have counted the number of elements kept in the instant variable called short_desc.

    3. I start reading the first text and here's the problem.

    The system reads the text from the first quotes without interruption as many times as there are counted items.

    So the system is not waiting.

    Besides, it does not take any more texts.

    What am I doing wrong here? I am asking for a hint.

  • In speech synthesis action instead of the 0 use loopindex

  • I agree that LoopIndex is a good idea. Thanks!

    But for me it's strange, because I have had the counter.

    So I change the one counter to another form of counting,

    but the counter remains a counter :-)

    Earlier, during getting to know Construct, I found information on how to use "wait" in the loop.

    So I put together the actions and the effect is:

    - The system says 3 times only the first sentence, it looks like LoopIndex did not work

    - "wait" is not run

    A very strange thing, because the logic looks OK. Maybe Construct needs something else?

    attach the file

  • The variables you're pulling out appear to be "0" "1" and "3" but you can't set those to be an int with the "" present, so they just become 0. A possible fix is to remove the "" around the numbers in the room variable, I think they're unnecessary anyway?

  • Thanks! I have removed the characters "" and now it is working with the appropriate intervals.

    This is great! But something with this speech synthesis is very strange.

    It speaks only the first sentence by X times.

    If I move the wait action below the speech synthesis, then it reads all the sentences, but does not keep the "wait" pauses.

    It looks like there will be either good breaks or good text :-D

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's a common misconception using wait in function calls or within loops.

    You can try to add the system action "wait for previous action to complete" directly below the wait x action.

  • Thanks!

    But where will I find such an action?

    For me, there is no such thing in Construct.

    please see:

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