The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Hi so Im working on a 2d platformer that has two different sets of items to collect that are kept track of with two different progress bars.
What is supposed to happen is that when the player picks up ten of the A Items, the A Progress bar is full and it changes scenes. Which does happen.
But I wanted to make it so that if the player had collected a certain amount of B Items they'd be sent to a different scene than usual.

this is the code on the player:

func _on_work_accomplished_3():
if Autoload.Glitches >= 3:
    get_tree().change_scene_to_file("res://level_fourtwo.tscn")
else:
    get_tree().change_scene_to_file("res://level_fourone.tscn")

the work Accomplished is the signal the A progress bar sends out when 10 items have been collected
and Glitches is the name of the B Item

this is the script I have on the progress bar:

    extends CanvasLayer

var works = 0
signal WorkAccomplished3

func _ready():
    $workprogress/ProgressBar.value = works
    if works == 10:
        WorkAccomplished3

func _on_work_done():
    works = works + 1
    _ready()
    if works == 10:
        emit_signal("WorkAccomplished3")

the work_done is a signal the A Item send when its been collected.

Everything works perfectly fine when I take the if else statement out of the code and just have it change scene, so I don't think its an issue with the Items or the Progress Bar

Godot version 4
in Engine by (45 points)

Are you saying that with the if/else, that the scene change isn't happening at all or that it's just not changing to the scene you expect?

Assuming you're getting into your _on_work_accomplished_3() function, you should be loading one of the two specified scenes based on the value of Autoload.Glitches. Assuming you're just getting the wrong scene, the cause is simply the value of Glitches variable.

A debug break point in that function should make it easy to see what's going wrong...

1 Answer

0 votes

Heres one thing you can do:

signal WorkAccomplished()

Func SendSignal():
    WorkAccomplished.emit(A_Items, B_Items)

and on your Other Script you would have in your Ready Function

TheScriptThatSendsTheSignal.WorkAccomplished.connect(WorkAccomplishedFunc)

func WorkAccomplishedFunc(A_Items, B_Items)
    If A_Items >= 10 and B_Items == (YourSpecificAmount):
        (LoadThisScene)
    elif A_Items >= 10:
        (LoadThisNoramlScene)

You send a SIgnal Containing your A and B Items, And on the Other Script you Catch the Signal, And then you Connect it to your LoadingScene Function... And from there you just Load whatever you want based on your Variables

by (109 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.