#ACCESSING FUNCTION FROM ANOTHER SCRIPT(GODOT)
86 messages · Page 1 of 1 (latest)
Signals are the proper way, if you want to call it directly you need reference to the player NODE. Currently you're trying to get the node from the FileSystem, this isn't going to work. You will need to get the node from the SCENE.
Can you help me? The tutorial about signals you sent earlier I find it not relatable to my problem as he is working with signals in the same node
Send me a screenshot of your scene
this is the one i need to access
and this is the button i will use to trigger the method
And does SelectDifficulty load as default?
Yes because you're not getting the player node correctly, one second.
Based on how you have this setup, you could create the player as an Autoload. That way it's always loaded no matter how you change your level
Go Project > Project Settings > Autoload. Select the path to your player SCENE, set the Node Name to Player then click Add
Now your Player scene will be loaded before everything else and will retain for the length of the game
Should look like this
well along those lines anyway
Now
now I cant run the whole code
to call the function
oh remove class_name
you set that with the autoload
class_name doesn't matter in this instance and Player SHOULD only be created once
It's based off the Singleton programming pattern but it's not exactly true to it. So whilst you can create more than one at runtime, I HIGHLY ADVISE NOT TO.
I have removed the class name
Cool so in your select_difficulty scripts
remove the get node functions and just call Player.change_difficulty()
Can you show me your autoload please?
hey can a signal cause a function to work?
I am thinking on creating three separate functions for easy medium and hard
yes that is their purpose,
can you teach me to do that?
lets step back and look at autoloads first
can I see how you configured it in your settings please?
because i thought it is hard to make a function work while giving a value too
I think autoload is gonna cause my game to not work
Autoload's will work, we just need to modify some code
my player has the movements in its script and the damage it get
Why don't you zip your project and send it to me
I'll make some adjustments and we can go from there
how to zip it?
Windows 10 or 11?
11
Right click project folder, compress to zip
alright, give me a bit. Need to download godot 3.5
i usually play scene from FirstScene
and it will go to menu and when you press start it will go to the game
now I am adding that selectdifficulty after that menu
I see you're already using signals in the Events autoload script
yeah I just followed a tutorial
gotcha
you did it??
Still going 🙂
download took forever
with 3.5.1
Alright
done
I've cleaned up your folder structure a bit, it was hard to navigate.
Instead of making the player an autoload, I created a gamemanger script.
You can use this to store values which you can access anywhere
u done it?
what is that
it's not best practice and you will most likely have issues further down the track, but I think you'll have other problems before you get to that.
I am just creating a project to pass
All i need is to create 3 levels
school assignment?
yes
Damn dude you are good
are there any other changes here other than you moving the max_health to the autoload?