if/otherwise condition problem I have.

dareek

  • Posts: 91
Help me please with my lack of programming knowledge.
The Scene have two actors.
I wanted to create scene's Event (input on Actor) that does:

'when the mouse is pressed on actor 1'
        make 'action 1'
       
        after 4 seconds 'make action 2'

            if 'mouse was pressed on actor 2'
                     set attribute to true

            otherwise
                     set attribute to false


Unfortunately it does not work.
The program runs like there is no if / otherwise condition. After setting attribute to true, sets it to false just after that.
I need the program to recognize if the actor 2 was pressed during 'make action 2' stage and if it was pressed, act on it by not doing 'otherwise' instruction.
How should I do that?


iNK

  • Posts: 68
Hi there; change your 'was pressed' in the second 'if' to 'is down'.
That should solve your problem. 'Is pressed' checks for the moment the button is pressed, not if it is held.

sdieters

  • Posts: 2068
@iNK, that will cause more problems thatn you owuld expect, since his code will be executed as many times as frames has passed while he holded his mouse button.

@dareek, so you want to have a time zone of 4 seconds in which you also have to press the second actor?
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

dareek

  • Posts: 91
@dareek, so you want to have a time zone of 4 seconds in which you also have to press the second actor?
[/quote]

Yes, 4 seconds in which I want the program to check if actor was pressed - and if it was, the program should do what follows attribute set to true - and if not, continue the program (go down to otherwise) and does what follows atribute set to false.
Not both one after another, like it does now.

iNK

  • Posts: 68
@sdieters: I think it should okay, because the second if, using 'is down', is housed within a 'was pressed', which is only triggered once per button press. If the outermost (first) conditional were an 'is down' then sure, that would be a problem.

Whoops, looks like I misunderstood what you were asking for, my bad.
This code (which I checked out in Stencyl this time) should check for clicks less than four seconds apart.
You could put some limitations to stop the timer from counting down below zero infinitely if you want, but it doesn't really affect the functionality.

//increment a timer variable to keep track of time since mouse button was pressed
created(do every 0.1 seconds (increment timer by -0.1))

//Check for a click and reset the timer.
always {
if(mouse was pressed on actor)
                 {
                       if(timer > 0) { set attribute to true; }
                       otherwise {set attribute to false;}
                       set timer to 4.0;
                }
}

dareek

  • Posts: 91
Quote
This code (which I checked out in Stencyl this time) should check for clicks less than four seconds apart.
You could put some limitations to stop the timer from counting down below zero infinitely if you want, but it doesn't really affect the functionality.

//increment a timer variable to keep track of time since mouse button was pressed
created(do every 0.1 seconds (increment timer by -0.1))

//Check for a click and reset the timer.
always {
if(mouse was pressed on actor)
                 {
                       if(timer > 0) { set attribute to true; }
                       otherwise {set attribute to false;}
                       set timer to 4.0;
                }
}

Thanks iNK for your time.
I will try to implement it into my program and check how it works.