Issues Accessing a Property
Asked Answered
S

2

0

Hey!

I'm encountering an issue with accessing a property within a function in my code, and I'm hoping someone can help me troubleshoot it.

Here's the problem: I have a standalone script called VehicleWheel2D.gd that defines a class called VehicleWheel2D. In this script, I'm initializing a variable vehicle to represent a node in my scene, specifically the Car node. I'm able to access vehicle and its properties, such as vehicle.Weight, anywhere in the script without any issues.

However, when I try to access vehicle.Weight from a custom function called calculate_weight_on_wheel() within an instance called front_right_wheel.gd of VehicleWheel2D, it's returning an error "Invalid get index 'Weight' on base 'Nil'". It seems like the variable is not accessible within the function, even though it has been initialized and is accessible elsewhere in the script.

I've checked the scope, timing of function calls, and variable initialization, but I'm still unable to pinpoint the exact cause of the issue. It seems like it might be related to where I'm accessing the variable from or a scoping problem, but I'm not sure.

If anyone has experienced a similar issue or has any insights on how to troubleshoot this further, I would greatly appreciate your input.

Thanks in advance for your help!

Spectacle answered 24/2 at 13:31 Comment(0)
V
0

on base 'Nil' means the object you are trying to access is null. You might want to check the way you get your wheel.

Viborg answered 24/2 at 16:28 Comment(0)
B
0

Spectacle can you post code? it may be as simple as a syntax error.

Bunns answered 24/2 at 18:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.