What I am trying to do may be silly or impossible even- but I’m making a status menu inspired by RPG Maker VX Ace and I want to connect a global script, Player_Stats, to my Status Menu. It works perfectly if I call it directly as a global script, however the game I am making will have 3 main characters which all will have their own global script for stats. (Reason I have their stats as a global script is because I use that script religiously in the turn-based combat part of my game). I was wondering if what I am doing is even possible or is there something I am missing? I keep getting this error:
This is what my Player_Data, custom resource is set up like:
Basically starting at “level_number” and down, none of those work at all.
How I have it set up is like Michael Games’ inventory system on youtube. It’s resource-based which I completely love.
For extra context:
slot_data = Player_Slot_Data (which just creates the variable player_data)
player_data = Player_Data (my custom resource which I have shown above)
player_stats = Script (this is the part that I’m iffy about and is causing errors)
This is why I have Player Data add a certain script because if this was a different character, then a different script would be applied. Is this even possible to do?
Maybe I am not understanding what you are saying completely and I do apologize if that is the case. Considering what I said above, would I still proceed with what you just showed me?
The error you’ve shown simply means you are trying to access the .Level property on an object which is a Script (and consequently has no such property). What you most likely meant to do was access the class instead. For that, you need to first instantiate it using Script.new().
If you need a different script (class) for different characters, that still works in the same way. You simply load the script you need, and you instantiate it. You can even do both on the same line, although you are missing out on some checks:
var my_custom_class: MyCustomClass = load(res://my_custom_class.gd).new()
That being said, for player stats and other such data, your are better off using custom resources instead of creating a new script for each player, which is what I understood from what you’ve said.
So instead of having: bob_stats.gd michael_stats.gd lyanna_stats.gd
You’d be better off having a Resource represeting the stats and using a unique instance of that for every character that needs stats. But since this wasn’t about the design in the first place, feel free to disregard this.
I agree, making them resources rather than scripts would honestly work easier and better which I may actually change just to adapt to that. I made them a global script to make it easier for the turn-based combat portion of my game but it honestly would still work with a resource now that I am thinking about it.