Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Pixelope |
I’m trying to make a template for collectibles in my game so I can use the template to create different collectibles (coins, health, mana etc.). Of course collecting one of these will update a global variable in my autoload/singleton script. I wanted to try to save time and use export variables to set these up without having to write/duplicate the same script for each item. I thought this was a great idea but I can’t figure out how to access a global variable within a script using an export var. I’ve searched online and maybe my phrasing is wrong because i’m drawing zero results so thought i’d ask here. Is this possible? Is there some clever creative workaround? Code below as an example:
export(int) var value
export(???) var collectible #This is where I want to be able to select the global variable.
func _on_Collectible_body_entered(body):
collectible += value
queue_free()
Any help would be appreciated.
I’ve never tried
export(Script)
////// I don’t quite understand but is that the problem?
or
Global.gd ==> collectible
/////// collectible // Global script
var number: int = 0
///////////////
onready var global = collectible
func _on_Collectible_body_entered(body):
global.number += 1
queue_free()
ramazan | 2022-02-06 20:54
I want to be able to select the global variable from the UI where export vars are displayed (on the right side of the UI). I’ve tried:
export(Script) var collectible
But that just lets me select a script, not select a variable within that script, I was hoping to access the global variables using the export var so I can select different global variables on the fly.
Pixelope | 2022-02-06 21:36
I told you I never tried. I’m sure you can handle the rest.
ramazan | 2022-02-06 21:50