what is this??????????????????????????????

0 favourites
  • 15 posts
  • I saw a demo about this

    [attachment=0:jpmyrxj1][/attachment:jpmyrxj1]

    may i ask what is this??

    seems very nice!

    i guees this will help me Make the code shorter

    any link let me know more about this plzzz

  • Conditionals.

    If touch.y is greater than gold then set the variable to touch.y-gold*gspeed, else set it to touch.y+gold*gspeed.

    With the ? indicating the if, and the : indicating the else.

    Basically test if something is true, if it is, then it sets it to the value following the question mark. If its not then it sets it to the value following the :.

    In this case it determines if you are going up, or down.

    At least I think that's how it works, the script does seem familiar.

  • if (Touch.Y>gold)

    gnew=Touch.Y-(gold*gspeed)

    else

    gnew=Touch.Y+(gold*gspeed)

  • Thankyou

    This is awesome!

  • newt

    tumira

    Is it possible to nest it like:

    if (Touch.Y=gold)

    gnew=Touch.Y-(gold*gspeed)

    else if (Touch.Y>gold)

    gnew=Touch.Y+(gold*gspeed)+a

    else if (Touch.Y<gold)

    gnew=Touch.Y+(gold*gspeed)+b

    else

    gnew=Touch.Y+(gold*gspeed)+c

    How do I write this using ?: operators? Can't seems to do this like I do it in MS Excel.

  • You don't want to do that.. The ternary ("?:") operator can be confusing to read, and nesting several of them is error prone and generally to be avoided. But yes it is possible. It will have many nested parentheses and be much less readable than the above. Some coding guidelines actually prohibit the use of this operator.

  • You don't want to do that.. The ternary ("?:") operator can be confusing to read, and nesting several of them is error prone and generally to be avoided. But yes it is possible. It will have many nested parentheses and be much less readable than the above. Some coding guidelines actually prohibit the use of this operator.

    Is that so? Hmm guess I have to use a lot of pickings then for a workaround on my current problem. codah can you show a sample of writing it correctly since you said it is possible, for the sake of knowledge.

  • Just check the syntax of ternary operators

    Condition?valueIfTrue:valueIfFalse

    so if you want to nest ternary operators, you can use parenthesis:

    Condition?(ConditionIfTrue?valueIfTrue:valueIfFalse):(ConditionIfFalse?valueIfTrue:valueIfFalse)

    and so on and so forth. Keep in mind you can also nest in the "condition" parameter, and you don't have to nest in both value (true/false).

    if (Touch.Y=gold)
    gnew=Touch.Y-(gold*gspeed)
    else if (Touch.Y>gold)
    gnew=Touch.Y+(gold*gspeed)+a
    else if (Touch.Y<gold)
    gnew=Touch.Y+(gold*gspeed)+b
    else 
    gnew=Touch.Y+(gold*gspeed)+c[/code:1kd3g4vc]
    can be written (just to make it easier to visualise) as
    [code:1kd3g4vc](Touch.Y=gold)?
    	true= gnew=Touch.Y-(gold*gspeed)
    	false=(Touch.Y>gold)?
    		true= gnew=Touch.Y+(gold*gspeed)+a
    		false=(Touch.Y<gold)?
    			true= gnew=Touch.Y+(gold*gspeed)+b
    			false= gnew=Touch.Y+(gold*gspeed)+c[/code:1kd3g4vc]
    which then becomes:
    [code:1kd3g4vc]gnew=(Touch.Y=gold)?(gnew=Touch.Y-(gold*gspeed)):((Touch.Y>gold)?(Touch.Y+(gold*gspeed)+a):((Touch.Y<gold)?(Touch.Y+(gold*gspeed)+b):(Touch.Y+(gold*gspeed)+c)))[/code:1kd3g4vc]
    
    As you can see, this is a nightmare to write, and outright impossible to understand. Avoid nesting ternary operators if at all possible.
  • Anybody gotten the inline or operator to work right yet?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This works

    (time<5 | time>10)?"not now":"now"[/code:gn5necf3]
  • It's too bad you can't do something like this Set text Function.Param(0) | "Placeholder"

    But instead have to do this Set text to Function.Param(0)?Function.param(0) : "Placeholder"

  • It's too bad you can't do something like this Set text Function.Param(0) | "Placeholder"

    But instead have to do this Set text to Function.Param(0)?Function.param(0) : "Placeholder"

    It's even worse in javascript. You have to do:

    (Function != undefined && Function.param != undefined && Function.param[0] != undefined)?Function.param[0]:"Placeholder"[/code:167kpfnq]
    because undefineds don't "cascade". If your function is undefined, then trying to access "param" will result in an error, since "undefined" doesn't have a "param" attribute. The logical thing would be that a non-existant attribute of a non-existant object would be undefined, but browsers disagree.
  • OMG folks these escalated so quickly! Thanks all for the good reads! Gonna play around with all these tomorrow, see how I can exploit all these.

  • This works

    (time<5 | time>10)?"not now":"now"[/code:1w1fam9a]
    

    OK, thanks.

    Guess I should stop using those for delimiters. lol

  • > codah can you show a sample of writing it correctly since you said it is possible, for the sake of knowledge.

    >

    I started to but it was late. You can see now why I didn't bother

    It's too bad you can't do something like this Set text Function.Param(0) | "Placeholder"

    I guess because that has another meaning.

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