Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Larington | |
Old Version | Published before Godot 3 was released. |
My current project involves buttons that are re-used frequently. I’m struggling with finding a good description of how to go about setting the object target for adding a signal connection where the object target is not self.
Node hierarchy is:
Gameplay
->Menu
—>Menu buttons
->QuestLog
—>TutorialQuest
GodotScript is:
# Sets up a button with some text and tells it what function the signal should link to.
func assignChoiceToButton(num, displayText, command):
get_node("ChoiceButton" + str(num)).show()
#print("ChoiceButton" + str(num))
get_node("ChoiceButton" + str(num)).set_text(displayText)
#print(displayText)
get_node("ChoiceButton" + str(num)).connect("pressed",self,command)
if(num == 1):
forgetsignal1 = command
if(num == 2):
forgetsignal2 = command
if(num == 3):
forgetsignal3 = command
if(num == 4):
forgetsignal4 = command
if(num == 5):
forgetsignal5 = command
if(num == 6):
forgetsignal6 = command
if(num == 7):
forgetsignal7 = command
func continuebuttonprompt(command):
resetchoicebuttons()
get_node("ChoiceButton7").connect("pressed",self,command)
get_node("ChoiceButton7").set_text("continue...")
forgetsignal7 = command
# This should clear the last signal applied to each of the buttons so they're ready for new signals to be assigned to them.
func resetchoicebuttons():
print("Choice Buttons Reset!")
if(forgetsignal1 != "emptyvalue"):
get_node("ChoiceButton1").disconnect("pressed",self,forgetsignal1)
if(forgetsignal2 != "emptyvalue"):
get_node("ChoiceButton2").disconnect("pressed",self,forgetsignal2)
if(forgetsignal3 != "emptyvalue"):
get_node("ChoiceButton3").disconnect("pressed",self,forgetsignal3)
if(forgetsignal4 != "emptyvalue"):
get_node("ChoiceButton4").disconnect("pressed",self,forgetsignal4)
if(forgetsignal5 != "emptyvalue"):
get_node("ChoiceButton5").disconnect("pressed",self,forgetsignal5)
if(forgetsignal6 != "emptyvalue"):
get_node("ChoiceButton6").disconnect("pressed",self,forgetsignal6)
if(forgetsignal7 != "emptyvalue"):
get_node("ChoiceButton7").disconnect("pressed",self,forgetsignal7)
get_node("ChoiceButton1").hide()
get_node("ChoiceButton2").hide()
get_node("ChoiceButton3").hide()
get_node("ChoiceButton4").hide()
get_node("ChoiceButton5").hide()
get_node("ChoiceButton6").hide()
get_node("ChoiceButton7").show()
forgetsignal1 = "emptyvalue"
forgetsignal2 = "emptyvalue"
forgetsignal3 = "emptyvalue"
forgetsignal4 = "emptyvalue"
forgetsignal5 = "emptyvalue"
forgetsignal6 = "emptyvalue"
forgetsignal7 = "emptyvalue"
So my question is, if I were trying to call the above code in “…/menu” from “…/QuestLog/TutorialQuest” what should I put instead of self for the object target? Thanks.
Random aside, for the moment I’ve cheated by copying the above code into the TutorialQuest node, but I’m not sure I want to be doing that for every single quest only to maybe rework it later.
Larington | 2017-01-12 17:17
Oh, in TutorialQuest I might setup a button like so:
assignQuestChoiceToButton(4, "I want to explore, curiosity drives me.", "stepOneAnswerB")
to then call
func stepOneAnswerB():
get_node("../../Menu").addTextOutput("You: I want to explore, curiosity drives me.")
get_node("../../Menu").addTextOutput("Guardsman: Exploration is not without its risks! I wish you luck in this endeavour!")
stepTwo()
Larington | 2017-01-12 17:34
also, you maybe could try to use match: statement instead of your ‘if’ conditional statements . not that it’d fix anything, but looks like a good use for it.
trumpetfish1 | 2018-04-25 04:34