I dont need this anymore, how do I delete this post

Godot Version 4.3

So I’m making a platformer where you’re freezing and you have to get to a campfire Quickly. to that I have a “Temperature” Scene wich looks like this:

Scene Tree

And a “Campfire” Scene wich looks like this:

image

I always import both scenes into the level, and everything worked great so far (I’ll leave the code at the bottom)

But for some Reason when I made a new Level and did everything the same way, The Capmfire doesn’t increase the temperature value anymore (It still does in the old level)

Code in TempDisp:

extends Node2D

var temp = 100
@onready var label: Label = $TempLabel
@onready var alarm: ColorRect = $"../Alarm"
@onready var background: ColorRect = $Background

var Under15 = false

var campfireScene = preload("res://scenes/campfire.tscn").instantiate()
var campfire = campfireScene.get_node("CampfireControll")

signal temp_zero

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	campfireScene.visible = false
	add_child(campfireScene)
	campfire.connect("tempGoUp", Callable(self, "_On_Temp_Go_Up"))
	print("Instanciated")
	


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
	temp -= 0.05 # 0.005 is a good value
	background.size.y = temp
	if label:
		label.text = str(int(temp))
	if temp <= 0.005: 
		emit_signal("temp_zero")
	if temp >= 99:
		temp -= 0.05
	if temp <= 10:
		Under15 = true
	else: if temp >= 10:
		Under15 = false
	if Under15 == true:
		alarm.visible = true
	else: if Under15 == false:
		alarm.visible = false

func _On_Temp_Go_Up():
		temp += 0.5
		print("Signal Receivd")

Code in CampfireControll

extends Node2D

var tempUp = false
signal tempGoUp
@onready var anim: AnimatedSprite2D = $AnimatedSprite2D

func _ready() -> void:
	anim.play("default")


func _process(_delta: float) -> void:
	if tempUp == true:
		emit_signal("tempGoUp")
		print("Signal Emitted")


func _on_area_2d_body_entered(body: Node2D) -> void:
	if body.name == "Player":
		print("Player Entered Capmfie Zone")
		tempUp = true


func _on_area_2d_body_exited(body: Node2D) -> void:
	if body.name == "Player":
		tempUp = false

can you upload pictures on the new level

@lowwaels98 Here you go:
Old Level


New Level

what do you mean?
The Capmfire doesn’t increase the temperature value anymore
to the label or the var temp

and one more thing why the
func _on_Temp_Go_Up():
temp += 0.5

it will only add one time 0.5 or you call it in
func _process():
to continue add value

ok let me explan the signal form campfire will active it ones and will not add more of then 0.5 but you can make it bool to is player in fire then active in the process function the temp Up var and if player exit area2d then stop adding that value to temp Up

@lowwaels98 The campfire doesn’t increase the temperature var ONLY in the new level, in the old one it works

1 Like

what do you mean?
The Capmfire doesn’t increase the temperature value anymore
to the label or the var temp

and one more thing why the
func _on_Temp_Go_Up():
temp += 0.5

it will only add one time 0.5 or you call it in
func _process():
to continue add value

ok let me explan the signal form campfire will active it ones and will not add more of then 0.5 but you can make it bool to is player in fire then active in the process function the temp Up var and if player exit area2d then stop adding that value to temp Up

if they player is in campfire its supposed to add 0.5 every frame

1 Like

it doing that but the signal when you add
camfire as child to the temperature
break

also does throw error and if throw error type it it will help

just tip: try print_debug(temperature) to debug the level and see what happen in both level and what value it type in the output

1 Like

there’s no errors

1 Like

so what the print_debug output of the var tempetature

where do i put that

in both code file in the process func just type
in file TempDisp and one in
print_debug(temp)
campfireControll file in the process function
print_debug(tempUp)

what you should see is
in file TempDisp
the value of temp 0.5 repeats itself in every frame
in file campfireControll
you should see the true or false value of the boolen also repeats it self every frame

just example for what it will shows
0.05
the file path TempDisp
false
the file path campefireControll

here if player enter camp fire while game run

0.1
the file path TempDisp
true
the file path campefireControll

and can you take image of it| it will more clear and ez to debug here

it says 51.5500000000028
At: res://Scripts/temp_cntrl.gd:27:_process()

1 Like

now try in new level you made and see what it output

same thing

1 Like

good now try in both level

print_tree_pretty() see if any changes in both tree other then what you add in the level like trap and other thing

ill try tmrw

HI @Morris . It would be great if you provided a .zip minimal project that will allow us to easily reproduce your problem.

I guess the following is worth trying to fix your issue:

  • when instantiating scene, it is good to set the owner of the child node for some benefits in editor, etc; see node property: owner
  • if you always instantiate the same scene (campfireScene is not exported) on ready, then maybe it makes sense to add the scene in the visual editor?

In the meantime, there are some suggestions you could follow in order to improve readability and maintainability of your code. They are not solution to your problem but should improve your project and make it less prone to errors.

These are as follow:

  • I think it’s better to connect signals to functions using the properties instead of names, e.g.
campfire.connect("tempGoUp", Callable(self, "_On_Temp_Go_Up"))
# vs
campfire.tempGoUp.connect(_On_Temp_Go_Up)

and has some editor benefits, like error notification if the connected function name is misspelled,

  • calculations in _process(delta: float) function should use delta value as _process function is not guaranteed to be called with constant interval.

Instead of estimating temp change, you could define:

var temp_change_speed: float = 1.0

func _process(delta: float) -> void:
    temp -= temp_change_speed * delta
    ... # now if your game freezes for some time, delta will reflect time since last update
  • signal emitting can be done using the signal instead of its name:
emit_signal("temp_zero")
# vs less error prone:
temp_zero.emit()
  • try to stick to one naming convention for easier code readability (I guess snake case for signal, variable and func names seems to be most consistent with Godot language):
campfireControll - camel case
temp_zero - snake case
_On_Temp_Go_Up - combination of both
  • use string formatting for fine grained control on what you display:
label.text = str(int(temp))
# vs
label.text = "%d" % temp
# or
label.text = "%2.0f" % temp

I hope this will be useful.

I saw you probably resolved your problem and don’t need it anymore.
Glad to hear it!

If you solved your problem, please share the cause and solution here, so anyone with similar problem may benefit from it.

You probably may mark any of the responses as solution to your issue, then probably you won’t get more replies.

If you do so, please restore previous topic.

1 Like

In Guideline page it is written that you can mark your question as solved.

Also, there is a “bell” icon to the right of the screen (PC). if you click it, you may choose not to be notified in future.