|Topic was automatically imported from the old Question2Answer platform.
Using Godot 3.1, I have
I want to use this function in so many sprites
So sprite1, it has to be attached as a script to it and so one, for each sprite I need to use that function on, it needs to be attached to the sprite
if play == True:
if (event is InputEventMouseButton and event.pressed and not event.is_echo() and event.button_index == BUTTON_LEFT) or (event is InputEventScreenTouch):
I want to pass a variable to it on every different sprite, the problems that I have
- I cannot pass variables to it, it only accepts event as an argument
- I cannot put it in another function
- I cannot as far as I know extend it
- I cannot store it in a global script file, it needs to be attached to a parent node
- I don’t want to copy paste
Can’t you use the same script on each sprite? You could add an exported variable to change this “sprite specific” argument. What do you mean by expand?
Jowan-Spooner | 2019-05-27 09:14
@Jowan-Spooner definitely has the right approach to this. You can make it slightly more extensible also by calling out to a virtual method where you have “#code here” if you wanted to, which you can then override in inherited scripts, if there was functionality that had to change drastically based on the sprite handling the click. See my answer on Facebook for more.
Kyle Szklenski | 2019-05-27 10:21