If I create the variables (price and currency) in an inner class (Cost) within my class (Cookie) for the sake of organization, they do not pop up in the Inspector despite getting no error message from using @export, meaning I cannot edit the variables for each specific node. What am I to do?
Depending on your âtop levelâ class name of âCookieâ, your Cost logic should be done differently, I donât think it should be a class. âCostâ being an âobjectâ based on a class doesnt seem right, âCostâ a simple math calculation.
BUT IF YOU REALLY WANT A CLASS FOR âCostâ, then I recommend putting it in a different script file. Then, you can declare a variable as a cost type: âvar cost: Costâ
EDIT:
Multiple classes within a class file IS POSSIBLE - they are called âinner classesâ. I dont think I would ever use them, maybe if I had multiple slightly different classes that inherit from the same parent class I can just throw them in one file.
Everything in there is just an example, just so I can learn how to use it in the future, so you donât have to think about the practicality of âCostâ itself.
Iâm aware about inner classes, if you read the title again, my post is exploring how they work. The point is how can I have editable variables while using Inner classes?
Now while typing this reply out, I actually figured out what seems to be a viable solution ToT. Iâll attach it in another reply for yâall to review
This is the solution I found to the problem. I create an instance of Cost and @export the variables contained in that instance. Iâm then able to edit those in the Inspector.
Let me know if you see anything wrong with this solution, or if there is a better one.
I still am curious why the variables did not show up in the inspector in the first screenshot, and what exactly @export did to those variables, since it ran that code without an Error message. It could be something worth looking into (preferably by someone more skilled than me).
At the end you may have to do the simple way by assigning an export variable to the objectâs property.
@export var my_cost:int
var obj_cost=Cost.new()
class Cost:
var cost: int
# Check if the key is being pressed in the _process function
func _process(delta):
if Input.is_action_pressed("ui_up"):
obj_cost.cost=my_cost
print(obj_cost.cost)