The function takes an incorrect value

0 favourites
  • 8 posts
From the Asset Store
Dungeon generation
$4 USD
60% off
Template for dungeon/maze generation, using wave function collapse
  • It seems that I have not understood the laying of conditions from Construct 3 blocks yet. I thought it was something like JavaScript, but in Construct 3 things are incomprehensible to me.

    Therefore, I am asking for an explanation of what is wrong in my thinking.

    I have this code:

    The speakOneDirection function is running.

    One parameter is passed with the value 0, i.e. the function should start speech synthesis.

    It should because the array "arr_potential_directions" on position 0 is written as 1:

    Meanwhile, the function works the other way around.

    The function does not start speech synthesis. The function will only work only if I write in the condition:

    Value at arr_potential_directions.At(arrayPosition) = 0

    And yet at position 0 in the array is saved 1!

    These are some miracles that even the oldest inhabitants of my village have not seen ;-)

    Does anyone understand this? :-D

  • The value at arr_potential_directions.At(arrayPosition) is 1, so youre saying if the value at 1 is 1. You needed simply value at arrayposition = 1 , not arr_potential_directions.at(arrayPosition) = 1.

  • Thanks for the answer! But I still do not understand.

    I'm sorry for tormenting with strange questions, but if I do not understand it, I will not be able to use array queries.

    I call the function by passing 0 in the parameter.

    This means that this condition:

    Value at arr_potential_directions.At(arrayPosition) = 1

    after inserting the value it will look like this:

    Value at arr_potential_directions.At(0) = 1

    and it does not work,

    it does not matter if I type arrayPosition or 0 in brackets.

    But if I save the condition in this way:

    Value at arr_potential_directions.At(1) = 1

    the speech synthesis will be launched.

    But my array looks like this:

    position / value:

    0 - 1

    1 - 0

    2 - 1

    3 - 1

    The code:

    Value at arr_potential_directions.At(0) = 1

    I understand:

    if the array "arr_potential_directions" at position 0 is the value 1 then run ...

    Am I thinking incorrectly?

  • I'll attempt to explain it better but it can be a little confusing even then :D

    You are using the condition compare at X of the array, so you're checking that a value at position X is = to some value.

    So the condition would normally be, compare at position 0 = 1, that's what you're trying to achieve.

    Instead you are passing a parameter through a function which is fine so its compare at position param = 0, so youre comparing if position 0 = 1.

    However in your events, instead of using a 0, or the parameter, you've used array.at(param) which is a value in the array.

    So you are saying if at POSITION : array.at(0) is equal to VALUE 1.

    array.at(0) is the value at X=0 which is 1.

    So it becomes a comparison, if X=1 is equal to 1 because you've replaced the position you want which is 0, with the value AT 0 in the array.

    Look at the condition without the function, you are comparing a POSITION is such a VALUE. You replaced what would normally be a 0, with a parameter 0. Which was my correction, it should just be arrayposition = 0. You've gone one step further inception style and said if the value at position(position(0)) in the array) so if the value at position(1) is 1, if X=1 is 1.

    array.at(x) is looking into the array for a value. It's confusing but think about it...

    Another way to look at it : Value at ( Value at array=0 ) = 1 becomes Value at 1 = 1. It should just be Value at (0) = 1 or Value at (param) = 1.

    If this doesn't get through I'm not sure what else to suggest. It should click after reading that I hope.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you so much for your patience! :-)

    I have read the entire thread 3 times

    and I broke down :-|

    I thought if I wrote in Construct:

    Value at arr_potential_directions.At(arrayPosition) = 1

    I will get something similar to the function in JS:

    var arrPotentialDirections = [1, 0, 1, 1];
    
    function speakOneDirection(arrayPosition) {
    	if (arrPotentialDirections[arrayPosition] === 1) {
    		console.log("speak");
    	} else {
    		console.log("sorry, I can't speak about it...");
    	}
    }
    
    speakOneDirection(0);
    

    Does it not work that way?

    How can I get something like this?

  • I gave you the fix already, just thought we were trying to get you to understand it. The fix is replace : 'array.at(param)' in the first box with 'param'. The condition you are using, the X position acts as like saying array.at so you don't need to use it again. I don't know how else to explain it.

    I think if you do want to write it in the format you have now you could use system compare 2 values haha.

  • Thank you so much for your patience! :-)

    I have read the entire thread 3 times

    and I broke down :-|

    I thought if I wrote in Construct:

    Value at arr_potential_directions.At(arrayPosition) = 1

    I will get something similar to the function in JS:

    > var arrPotentialDirections = [1, 0, 1, 1];
    
    function speakOneDirection(arrayPosition) {
    	if (arrPotentialDirections[arrayPosition] === 1) {
    		console.log("speak");
    	} else {
    		console.log("sorry, I can't speak about it...");
    	}
    }
    
    speakOneDirection(0);
    

    Does it not work that way?

    How can I get something like this?

    Your probably looking for something like this, with functions

    But as said before, there are maybe easier ways to do it

    Cheers

  • Plinkie!

    That's exactly what it was about:

    The fix is replace : 'array.at(param)' in the first box with 'param'.

    I was depressed because I saw only two solutions:

    - I'm stupid

    - or Construct 3 was stupidly written

    Fortunately, you pulled me out of it!

    I was just overthinking :-D :-D :-D

    Thanks a lot!

    Sizcoz - thanks for your suggest, but the solution was mega simple, as Plinkie wrote before.

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