Advertisement
otorp2

func call on mouseclick

Aug 2nd, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. A simple way to do this will be to use the yield.
  2.  
  3. First define a signal by
  4.  
  5. signal mouse_click
  6. Then you need to listen for the mouse click in _input process.
  7.  
  8. func _input(event):
  9. if(event.type ==InputEvent.MOUSE_BUTTON and event.is_pressed() and not event.is_echo()):
  10. emit_signal("mouse_click")
  11. Then inside myFn1,
  12.  
  13. function myFn1():
  14. print("this will run right away")
  15. yield(self,"mouse_click")
  16. print("this will wait for mouse click")
  17. Hope this works, please check this because I'm typing on mobile.
  18.  
  19. answered Jul 14 by vinod (382 points)
  20. Comment
  21. As I mentioned in my post, I have already tried coroutines. All this does is pause myFn1() mid-execution, but for some reason doesn't stop myFn2() from being executed normally.
  22. I don't know why, but that's what happens.
  23.  
  24. commented Jul 14 by Adham
  25.  
  26. I am using coroutines without problems.
  27.  
  28. How are you calling the two functions?
  29. I'm just making sure of something.
  30.  
  31. If you are calling like this,
  32.  
  33. myFn1()
  34. myFn2()
  35. and the yield is inside myFn1, then both functions will run without waiting.
  36.  
  37. You need to call like this,
  38.  
  39. myFn1()
  40. yield....
  41. myFn2()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement