none
Controls RRS feed

  • Question

  • NameChar()
    Sub NameChar
    GraphicsWindow.BrushColor="Black"
    GraphicsWindow.Width=310
    GraphicsWindow.Height=170
    GraphicsWindow.DrawBoundText(90,10,300,"Welcome To Factions!")
    GraphicsWindow.DrawBoundText(60,50,300,"What do want your name to be?")

    NameTextBox=Controls.AddTextBox(80,90)
    NameButton=Controls.AddButton("Press when you have typed the name you want",10,130)
    Controls.ButtonClicked = CheckFClick
    EndSub

    Sub CheckFClick
      NameC=Controls.LastClickedButton
       TextWindow.WriteLine(NameC)
       If NameC="Button1" Then
      CharacterN=Controls.GetTextBoxText("TextBox1")
      Goto Menu
    EndIf
    endsub

    It doesnt seem to go to menu even though i can see that NameC="Button1" in my textwindow??

    Can you fix this or tell me a diffrent way of doing it, With out removing the Subroutines?

    Wednesday, November 16, 2011 1:42 AM

Answers

  • Although this (FPK437) works it is generally not a good idea (it is a BAD idea) to GoTo into or out of a Subroutine - it will corrupt the call stack - the reason it doesn't crash in this case is that the stack never unwinds and we are adding to the stack, leaving dangling call stack entries which mount up.  This doesn't crash immediately, but will when the call stack is exhausted - my strong recommendation is not to GoTo in or out of a subroutine - can't put it ant stronger than that - it will cause misery.

    There are also some consequences of the differences between ordinary and event subroutine, for example the following won't compile:

     

    next:
    Test1()
    
    Sub Test1
      Goto next
    EndSub

    On my PC the call stack is 2390 - Quite a lot of button presses, but not long in a game with 50 fps update for example.

     

    count = 0
    Recursion()
    
    Sub Recursion
      count = count+1
      TextWindow.WriteLine(count)
      Recursion()
    EndSub

    This is how I would recommend doing it, import FPK437-0.
    Thursday, November 17, 2011 7:41 PM
    Moderator

All replies

  • CharacterN=Controls.GetTextBoxText(NameTextBox)
       ' TextWindow.WriteLine(CharacterN)  ' to confirm
    Wednesday, November 16, 2011 8:52 AM
    Answerer
  • it still not going to menu though?

    even though i can see the if statement working?

     

    Wednesday, November 16, 2011 10:58 AM
  • In addition to NaochanOn, try the following - note the bold bits where changes were made and comments.

    Sub CheckFClick
      NameC=Controls.LastClickedButton
      'TextWindow.WriteLine(NameC) 'Commented out
      If NameC=NameButton Then
        CharacterN=Controls.GetTextBoxText(NameTextBox)
        GraphicsWindow.ShowMessage(CharacterN,"Information") 'Show the result
        'Goto Menu 'You cannot do a Goto that jumps in or out of a subroutine
      EndIf
    endsub


    Wednesday, November 16, 2011 7:16 PM
    Moderator
  • since i can't do goto menu im just going to make the menu a subroutine,Thanks for the info.
    Wednesday, November 16, 2011 10:12 PM
  • If you want to use "goto menu"  try this.  FPK437

    PC is waiting after NameChar().

    Thursday, November 17, 2011 1:27 AM
    Answerer
  • Although this (FPK437) works it is generally not a good idea (it is a BAD idea) to GoTo into or out of a Subroutine - it will corrupt the call stack - the reason it doesn't crash in this case is that the stack never unwinds and we are adding to the stack, leaving dangling call stack entries which mount up.  This doesn't crash immediately, but will when the call stack is exhausted - my strong recommendation is not to GoTo in or out of a subroutine - can't put it ant stronger than that - it will cause misery.

    There are also some consequences of the differences between ordinary and event subroutine, for example the following won't compile:

     

    next:
    Test1()
    
    Sub Test1
      Goto next
    EndSub

    On my PC the call stack is 2390 - Quite a lot of button presses, but not long in a game with 50 fps update for example.

     

    count = 0
    Recursion()
    
    Sub Recursion
      count = count+1
      TextWindow.WriteLine(count)
      Recursion()
    EndSub

    This is how I would recommend doing it, import FPK437-0.
    Thursday, November 17, 2011 7:41 PM
    Moderator
  • In other BASIC which I was using before, a trouble had not occurred in such a way.
    However, since it turned out that it crashes in SB as you showed, let's make sure not to use it from now on.
    Friday, November 18, 2011 7:06 AM
    Answerer