[SOLVED] Calling methods every n seconds in scene.update()
Hi, I want to know if it is possible to call a method every n seconds (example: every 1 second) in scene.update.
If this is possible, can you please provide the right way of going about this?
Thank you, and God bless you all abundantly in Jesus Christ!!!
see my example, the .text attribute is used to update text.
note, you probably want to set the anchor_point=(0,0) for left justification, unless you want the text centered.
Lambdas accept multiple args
lambda arg1,arg2:some_function(arg1, arg2)
If you do a lot of these types of things, I (once again) promote the scripter, which works with views and scenes, for example like this:
from scene import * from scripter import * class MyScene (Scene): def setup(self): self.ship = SpriteNode('spc:PlayerShip1Orange') self.ship.position = self.size / 2 self.add_child(self.ship) self.do_a_thing_every_second() @script def do_a_thing_every_second(self): while(True): print('do the thing') yield 1.0 run(MyScene())
@mikael Hi friend, I am having trouble with importing scripter? It says that this is invalid syntax:
from scripter import *
@Splefix, as an unfortunate barrier to entry, you need to download
scripter.pyfrom the link and place it in your site-packages.
@mikael Hey sorry man, I am new to Pythonista, especially concerning the installation you are talking about. Can you please help me install scripter? If it isn’t too much trouble. I haven’t worked with github before either.
@Splefix, do you have stash installed? If not, recommend that you install it anyway. (Google for ”pythonista stash” for instructions).
When you have it, start stash, then:
StaSh v0.7.0 on python 3.6.1 Warning: you are running StaSh in python3. Some commands may not work correctly in python3. Please help us improving StaSh by reporting bugs on github. Tip: Bring a background job to foreground with fg JOB_ID [~/Documents]$ cd site-packages [site-packages]$ wget https://raw.githubusercontent.com/mikaelho/scripter/master/scripter.py
@mikael Hey man, I did that, but now I get the following error:
- Name 'script' is not defined
This concerns the following code:
@script def do_a_thing_every_second(self): if self.auto_amount >= 1: while(True): spawn_bubble(self, False) yield 1.0
@Splefix, do you have the file in site-packages and still have the import statement at the top? Import statement with the asterisk and not just
Yes, but it is okay. I will just use the time module instead. Thank you all for your help. God bless you all in Jesus Christ’s MIGHTY NAME!!!!