|
|
|
![:bust_in_silhouette: :bust_in_silhouette:](https://forum.godotengine.org/images/emoji/twitter/bust_in_silhouette.png?v=12) |
Reply From: |
Zylann |
You can try to split your scene in two, so you can reset one part without deleting the other.
Another way is to use a singleton (auto-load) which will contain the part you don’t want to reset (but that would be the same solution as the first).
You could also come up with your own way of resetting, like having a script with a reset
function on the parts that are “resetable”, and then call this function individually on nodes you want to reset.
can you give me an example
If you have a scene for the game and a scene for a round of the battle, you could do this:
# Get the current round that may have finished
var last_round = get_node("Round")
# Keeping variables outside the Round scene allows us to preserve them between rounds
player_scores[last_round.winner] += 1
# Destroy the previous round
remove_child(last_round)
last_round.call_deferred("free")
# Create the next round
var next_round = preload("round.tscn").instance()
add_child(next_round)
You could also have players as two nodes, and the battle as a third one.
This is just one way of doing it, I don’t know your game enough to give you a more specialized solution.
Zylann | 2018-02-27 20:11
This is my battle scene code i want it so when the player chooses a button(one of the Choices) the func answerlocation() will reset and get new a new question and answer
extends Control
onready var QnA=get_node("QnA")
func answerlocation():
get_node("Question").set_text(QnA.questions())
var num=randi()%4
for x in range(1):
num
if num==0:
get_node("Choice1").connect("pressed",get_node("Player"),"attack", [get_node("Enemy")])
get_node("Choice1").set_text(QnA.answers())
get_node("Choice2").connect("pressed",get_node("Enemy"),"attack",[get_node("Player")])
get_node("Choice2").set_text("wrong")
get_node("Choice3").connect("pressed",get_node("Enemy"),"attack",[get_node("Player")])
get_node("Choice3").set_text("wrong")
get_node("Choice4").connect("pressed",get_node("Enemy"),"attack",[get_node("Player")])
get_node("Choice4").set_text("wrong")
elif num==1:
get_node("Choice2").connect("pressed",get_node("Player"),"attack",[get_node("Enemy")])
get_node("Choice2").set_text(QnA.answers())
get_node("Choice1").connect("pressed",get_node("Enemy"),"attack",[get_node("Player")])
get_node("Choice1").set_text("wrong")
get_node("Choice3").connect("pressed",get_node("Enemy"),"attack",[get_node("Player")])
get_node("Choice3").set_text("wrong")
get_node("Choice4").connect("pressed",get_node("Enemy"),"attack",[get_node("Player")])
get_node("Choice4").set_text("wrong")
elif num==2:
get_node("Choice3").connect("pressed",get_node("Player"),"attack",[get_node("Enemy")])
get_node("Choice3").set_text(QnA.answers())
get_node("Choice2").connect("pressed",get_node("Enemy"),"attack",[get_node("Player")])
get_node("Choice2").set_text("wrong")
get_node("Choice1").connect("pressed",get_node("Enemy"),"attack",[get_node("Player")])
get_node("Choice1").set_text("wrong")
get_node("Choice4").connect("pressed",get_node("Enemy"),"attack",[get_node("Player")])
get_node("Choice4").set_text("wrong")
elif num==3:
get_node("Choice4").connect("pressed",get_node("Player"),"attack",[get_node("Enemy")])
get_node("Choice4").set_text(QnA.answers())
get_node("Choice2").connect("pressed",get_node("Enemy"),"attack",[get_node("Player")])
get_node("Choice2").set_text("wrong")
get_node("Choice3").connect("pressed",get_node("Enemy"),"attack",[get_node("Player")])
get_node("Choice3").set_text("wrong")
get_node("Choice1").connect("pressed",get_node("Enemy"),"attack",[get_node("Player")])
get_node("Choice1").set_text("wrong")
func _ready():
answerlocation()
Also if im going to make a round function does it have to be a round node or i can putting as a round script in my battle scene(main scene)
I’m confused about what this code really attempts to achieve… If I understand correctly, what answerlocation()
does is to pick a new random question and initialize the choices for it?
Zylann | 2018-02-28 19:55
that is partially correct the answerlocation() is the one that resets the new location for the answers so that the answer will not be in the same location every time. im getting my questions from another script node.
if you need it to understand my code better please ask.