How do I address an object in an expression?

0 favourites
  • 4 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Hi!

    I'm trying to access the "Text" from an input field via it's instance variable.

    But it doesn't work as expected.

    I have two input fields (same object, but a diffrent Instance Variable ("InputType").

    If I press login it logs following:

    "Email: " & input(input.InputType = "Email").Text & " / Password: " & input(input.InputType = "Password").Text[/code:1ijvrw6u]
    
    But the output is like this.
    [img="https://shatter-box.com/wp-content/uploads/2016/07/input_fields_test_error.png"]
    
    So the [code:1ijvrw6u]input(input.InputType = "Email").Text[/code:1ijvrw6u] returns the password and the [code:1ijvrw6u]& input(input.InputType = "Password").Text[/code:1ijvrw6u] returns the email.
    I double checked my input fields. I do not know what to do at this point. Maybe 

    Ashley has an idea?[/p] [/p] I uploaded the capx file on my dropbox account.[/p] [url=https://www.dropbox.com/s/5zn7pfwyad5mx7l/testcase_expression_issue.capx?dl=1]https://www.dropbox.com/s/5zn7pfwyad5mx ... .capx?dl=1[/url][/p] [/p] Thank you!

  • Most value evaluating conditions pair up with expressions.

    There is the condition Sprite > Compare X and its pairing expression Sprite.X.

    So, u can use Sprite > Compare X .. or System > Compare two values (using Sprite.X).

    The first one will filter the picklist (SOL), de second one will not filter the picklist.

    There is a reason why i started like this.

    Because in the same logic ....

    You have the condition System > Pick nth Instance and its pairing expression sprite(nth).xxxxx

    'nth' is in fact the IID for an instance of an object in a certain picklist (SOL), it is a zero based index, and it is a number.

    If you have all instances of an object picked, this IID represents also the order that they are created.

    And now some more background info.

    Some conditions (but also expressions) have only a meaning when used with a certain condition.

    The condition 'pick nth instance' has no meaning without a condition that actual picks items (make a SOL), so sprite(nth).xxxxx has no meaning without a pick.

    The expresssion loopindex("i") has not meaning without a loop condition.

    The expression array.curX has no meaning without a 'for each element' condition.

    So, for you to adress an nth instance by instance(nth).xxxx, you should use a 'pick all' (althaught for only 1 line of code as in your example this is redunctant).

    Then using the expression goes like this ...

    "Email: " & input(0).Text & " / Password: " & input(1).Text

    Beeing 0 the IDD of the first instance of the sprite input, 1 the IDD of the second sprite input.

    You can use logical expressions. Like :

    input.InputType = "Email" ? 1 : 0

    But it is a bit weird to use this to return an IID.

  • Most value evaluating conditions pair up with expressions.

    There is the condition Sprite > Compare X and its pairing expression Sprite.X.

    So, u can use Sprite > Compare X .. or System > Compare two values (using Sprite.X).

    The first one will filter the picklist (SOL), de second one will not filter the picklist.

    There is a reason why i started like this.

    Because in the same logic ....

    You have the condition System > Pick nth Instance and its pairing expression sprite(nth).xxxxx

    'nth' is in fact the IID for an instance of an object in a certain picklist (SOL), it is a zero based index, and it is a number.

    If you have all instances of an object picked, this IID represents also the order that they are created.

    And now some more background info.

    Some conditions (but also expressions) have only a meaning when used with a certain condition.

    The condition 'pick nth instance' has no meaning without a condition that actual picks items (make a SOL), so sprite(nth).xxxxx has no meaning without a pick.

    The expresssion loopindex("i") has not meaning without a loop condition.

    The expression array.curX has no meaning without a 'for each element' condition.

    So, for you to adress an nth instance by instance(nth).xxxx, you should use a 'pick all' (althaught for only 1 line of code as in your example this is redunctant).

    Then using the expression goes like this ...

    "Email: " & input(0).Text & " / Password: " & input(1).Text

    Beeing 0 the IDD of the first instance of the sprite input, 1 the IDD of the second sprite input.

    You can use logical expressions. Like :

    input.InputType = "Email" ? 1 : 0

    But it is a bit weird to use this to return an IID.

    Hi 99Instances2Go

    Thank you very much for your detailed respone.

    I know that I easily can get it via it's IID. But the game generates input fields depending on the current form (register or login). So I wanted to pick the corresponding input field depending on its instance variable.

    So I thought I could pick an instance by the value of an instance variable of it.

    Now I altered my code to this.

    "Email: " & input(input.InputType = "Email" ? input.IID : -1).Text & " / Password: " & input(input.InputType = "Password" ? input.IID : -1).Text[/code:pzbwid6f]
    
    This worked out for me  Thank you for your help!
    
    Regards
    Andy
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 99Instances2Go is pretty much spot on. The form Object(n).Expression uses 'n' as an instance index. In this case you are passing a comparison of the input type. This is completely unrelated to the rest of the expression, it will just evaluate 'n' as a number to find the instance index. Since you pass a comparison it returns a boolean, which in C2 is just 0 or 1. If C2 had stricter type rules, this would not be allowed at all, since often you're not allowed to pass a boolean in place of a number. Anyway this produces an instance index which has nothing to do with the original comparison! Your example is probably confusing you because it is obvious what you want it to do, but it doesn't do that.

    TBH it's easier to just pick the instances you want with conditions - I'm not convinced the Object(n).Expression feature is worth the complexity...

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