Variable in dialogic not updated (in scripts is working but in dialogic is 0.0)

Godot Version

Godot 4.6

Question

(I just started my coding journey a few days ago.)

i just want

if score>=99 say perfect

score>=75 say it’s working

score>=50 say it’s ok right

Else say try again

score when print it’s working but in dialogic is 0.0

extends Node2D

@onready var salt_line = $Line2D
@onready var bottle_visual = $salt_buttom
@onready var bottle_area = $salt_buttom/BottleArea

# --- ตัวแปรหลัก ---
var start_pos : Vector2
var is_selected = false 
var is_drawing = false  

# --- ตัวแปรระบบคะแนนและทิศทาง ---
var center_point : Vector2
var penalty_points : float = 0.0
var has_warned : bool = false

func _ready():
	start_pos = bottle_visual.global_position

func _input(event):
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
		if event.pressed:
			var mouse_pos = get_global_mouse_position()
			
			if not is_selected:
				if is_mouse_over_bottle():
					is_selected = true
					bottle_visual.modulate = Color(1.5, 1.5, 1.5)
					bottle_visual.global_position = start_pos + Vector2(0, -30)
			else:
				is_drawing = true
				penalty_points = 0.0
				has_warned = false
				salt_line.clear_points()
				center_point = mouse_pos 
				bottle_visual.global_position = mouse_pos + Vector2(0, -30)
		else:
			# --- จังหวะปล่อยเมาส์ (ส่งคะแนน) ---
			if is_drawing:
				is_drawing = false
				is_selected = false 
				
				var final_score = calculate_final_score()
				
				if Engine.has_singleton("Dialogic"):
					
					# 1. ส่งค่าทศนิยมเข้าไปโดยตรง
					Dialogic.VAR.set_variable("FinalScore",round(final_score))
					
					# 2. รอให้ระบบจัดการ Variable เสร็จสิ้นก่อนเริ่ม Timeline
				await get_tree().process_frame
				await get_tree().process_frame
				await get_tree().process_frame
					# 3. เริ่ม Timeline
				Dialogic.start("SaltEvaluation")
				
				print("คะแนนส่งออก: ", final_score)

func _process(_delta):
	if is_drawing:
		var m_pos = get_global_mouse_position()
		bottle_visual.global_position = m_pos + Vector2(0, -30)
		
		if salt_line.points.size() > 0:
			var last_p = salt_line.points[-1]
			var cross = (last_p - center_point).cross(m_pos - center_point)
			if cross < 0: 
				penalty_points += 0.2
				if not has_warned:
					print("วนผิดด้าน!")
					has_warned = true
		
		if salt_line.points.size() == 0 or m_pos.distance_to(salt_line.points[-1]) > 10:
			salt_line.add_point(m_pos)
	else:
		if not is_selected:
			bottle_visual.modulate = Color(1, 1, 1)
			bottle_visual.global_position = bottle_visual.global_position.lerp(start_pos, 0.1)

# --- ฟังก์ชันช่วย ---

func is_mouse_over_bottle() -> bool:
	var shapes = bottle_area.get_world_2d().direct_space_state
	var parameters = PhysicsPointQueryParameters2D.new()
	parameters.position = get_global_mouse_position()
	parameters.collide_with_areas = true
	var results = shapes.intersect_point(parameters)
	for result in results:
		if result.collider == bottle_area: return true
	return false

func calculate_final_score() -> float:
	var points = salt_line.points
	if points.size() < 10: return 0.0
	
	var real_center = Vector2.ZERO
	for p in points: real_center += p
	real_center /= points.size()
	
	var avg_dist = 0.0
	for p in points: avg_dist += real_center.distance_to(p)
	avg_dist /= points.size()
	
	var deviation = 0.0
	for p in points: deviation += abs(real_center.distance_to(p) - avg_dist)
	
	var roundness = 100.0 - (deviation / points.size() * 3.0)
	var total = roundness - penalty_points
	return clamp(total, 0.0, 100.0)

It’s a good thing you’ve provided a script, but it would be helpful to see the Dialogic side (the timeline) as well.

I believe this is the line in question, correct?

I’m not too familiar with Dialogic, but you might need to set up a Dialogic Variable for this. Have a look at the Dialogic documentation on variables.

Having a look at theset_variable()method insubsystem_variables.gd, it seems like it should give you an error if the variable does not exist (“[Dialogic] Tried setting non-existant variable …”)

Variable is FinalScore but the ui in mobile too small