Here's the gist of accessing objects and picked objects in python:
documentation-for-span-class-posthilit-python-span-scripting_p622892?#p622892
Behaviors are accessed like so. If the object is called Sprite and the behavior is Platform then the behavior is SpritePlatform from python. Be aware python is case sensitive.
To access the behavior paired with the object you do it like so depending on the way you access Sprite.
Sprite
SpritePlatform
Sprite
SpritePlatform
SOL.Sprite
SOL.SpritePlatform
SOL.Sprite
SOL.SpritePlatform
You can also see a list of them from python by setting some text to the dictionary with a snippet like this:
Python("str(dir())")
Also you can look at a list of methods available in a similar way:
Python("str(dir(SpritePlatform))")
Hey,
Is Sprite[x] supposed to pick the "Sprite x" ?
Because when I create for example 10 Sprite, if I do Sprite[0].SetX(1) and then Sprite[4].SetX(25) -> it's always the same Sprite object that moves :/
EDIT : It looks like that if I create those sprite in the Construct Layout Editor (copy paste 5 time the sprite), the Sprite[x] thing is working BUT if I create those using python :
System.CreateByName("Sprite", 1, 100, 100)
[/code:2d8t12t0]
then the Sprite[x] thing is giving me this error :
[quote:2d8t12t0]
---------------------------
Error
---------------------------
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\A\F\G\SRC\main.py", line 30, in <module>
execfile("src/load_game.py")
File "src/load_game.py", line 5, in <module>
Sprite[1].SetX(10)
File "<string>", line 911, in __getitem__
IndexError
---------------------------
OK
---------------------------
my python code is
[code:2d8t12t0]
System.CreateByName("Sprite", 1, 500, 200)
Sprite[1].SetX(10)
[/code:2d8t12t0]
There is 1 sprite instance created with the layout editor (Sprite[0]) and one with python (supposed to be Sprite[1])
[h2][b]EDIT 2 :[/b][/h2] Sprite[x] seems to works only when ALL the code of "load_game.py" was executed, is there a way to access Sprite[x] before all the code was executed (except SOL.Sprite) ?