I'm not correctly modifying these variables on a different node, please help me understand

Godot Version

Stable Release 4.5

Question

`
P.S. idk why the Syntax Highlights are broken on this, if somebody can tell me I’ll make the edit so it’s more readable.

So I’ve got a script where I pick up an object, drag it, release click a node to set it down on, that part works fine, but then I want the node it gets set down on to have a variable that decides which nodes the object will be moved to next:

extends Node3D

var path_direction : Array = [$"../position_node_1",$"../position_node_2"]

and the script that does the raycasting and dragging around (minus everything not relevant to the task at hand such as multiple raycast functions)

extends Node3D

var screen_size : Vector2

var card_dragging : Variant = null
var plane : Variant = null
var d_node : Variant = null

var card_acceleration : float
var mouse : Vector2 = Vector2()
const DIST : int = 1000

var exclude_list : Array
var plane_exclude : Array
var inactives_list_exclude : Array
var inactives_list : Array

func _input(event : Variant) -> void:
	mouse = event.position
	
	if event is InputEventMouseMotion:
		var plane_collider : Variant = raycast_check_for_plane_location(mouse)
		if plane_collider:
			plane = plane_collider
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
		if event.pressed:
			print('CLICK')
			print(exclude_list)
			var card_collider : Variant = raycast_check_for_card_3d(mouse)
			if card_collider:
				card_dragging = card_collider
		else:
			print('RELEASED')
			var dungeon_node : Variant = raycast_check_for_dungeon_node(mouse)
			if dungeon_node:
				d_node = dungeon_node
				inactives_list_exclude.append_array([card_dragging.rid])
				inactives_list.append_array([card_dragging])

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(_delta: float) -> void:
	if plane:
		if card_dragging:
			var drag_position : Vector3 = Vector3(plane.x/1.6,0.1,plane.z/1.5)
			card_dragging.collider.position = drag_position
			if d_node:
				card_dragging.card_dungeon_address = d_node
				card_dragging.card_inactive_state = true
				d_node = null

and in the script for the instanced object:

extends RigidBody3D

var card_dungeon_address : Variant = null
var card_inactive_state : bool = false
var card_node_interact : bool = false

var next_node : Variant

#potentially make a custom event here and have it set the
#self.position to a variable so that it doesn't do that every frame.

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
	if card_inactive_state and card_dungeon_address and not card_node_interact:
		next_node = card_dungeon_address.path_direction.pick_random()
		self.position = Vector3(move_toward(self.position.x, next_node.position.x,30),-0.15,move_toward(self.position.x, next_node.position.x,30))
		if self.position == next_node.position:
			print('next noding info:')
			print(card_dungeon_address)
			print(next_node.position)
			#add a colliding check with a dungeon node and make it the new 
	elif card_inactive_state and card_node_interact:
		print('not yet implemented behavior')
	else:
		print('card inactive state: ', card_inactive_state)
		print('card dungeon address: ', card_dungeon_address)
		print('card node interact: ', card_node_interact)

but after the card gets set down, it should be inactive and the d_node should have been set, but the prints are showing false, null, false on the card.

`

1 Like

not a expert but i need to know that you mean,

you are trying to make a card game and had found ways to pick and drop it, but you wanted the card to sit on top of other card and new card on top of it. is it.

or there is something else,

tell me i’ll try to find a way

from what context i understand, you have variable of card (which you have created instance of) which should show new values, but they show default values like null, false and false.

try to create and add_child instance and then put values

var card : Rigidbody3D = preload("res://somewhere.tscn");
var create_instance() -> void:
    var ins = card.instantiate();
    add_child(ins);
    #after update it
    ins.card_inactive_state = true;

if this is the case it should work

Ignore the word card

Ignore every variable name in the code, just treat them as variables

I want to take the value from script A and set that value on script B

It isn’t working when I tried it above.

I’ll try the preload add_child idea soon.

1 Like

ohh i see.. you don’t have anything to do with create a new instance..

As i see i can’t find any mistake in you’re code, maybe it is in raycast_check_for_card_3d() that. this function is not returning a reference of Variant.

check if a variant is returning from this function raycast_check_for_card_3d() which you have create.

share me the code raycast_check_for_card_3d() function.

for debugging propose can you do following things :-

  1. create a name export variable and obj_name and name them individually for card to test.
  2. as you get return from raycast_check_for_plane_location(mouse) this just use print(plane_collider.obj_name).
  3. if above condition works check if in physics_process if all the “if-else“ statement are working

it is more likely debugging problem.

1 Like