Results 1 to 10 of 10

Thread: Calling a button only after conditions have been met?

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    43

    Calling a button only after conditions have been met?

    I'm new to VB and writing a text based rpg using many forms. In one of my forms I want the npc to give information to the player, but only after the player has gone to the town square.

    I was going to put this npc information in a button that the player clicks and a message box shows up.

    The problem I'm having is that the player could go to the npc before they go to the town square. I would like to have the npc information button hidden on the form until the player has gone to the town square. Then and only then can the player see the button that would allow the player to get the information.

    Is it even a possibility to hide the button until certain conditions have been met?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Calling a button only after conditions have been met?

    Unsure what version of VB you are using, but controls have Visible property that can be set during runtime. Suggest setting it to False initially, then when player goes to town center, set property to true? If that doesn't work, you may need to show us some relevant code you are using
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    43

    Re: Calling a button only after conditions have been met?

    Thanks. I'm using VS 2010 with VB. I will try using the properties and changing the value of the property if the player has been to the town square or not. Thanks for the help!!

  4. #4
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Calling a button only after conditions have been met?

    You would need the npc to have a flag. Not just him but all of em.

    vb.net Code:
    1. Public Structure NPC_Type
    2.      Dim X As Integer 'X Position of NPC on map
    3.      Dim Y As Integer 'Y Position of NPC on map
    4.      Dim Met_Flag As Boolean
    5. End Structure
    6.  
    7. Private NPC(Your_Number_of_NPCs_Here) As NPC_Type

    Then in your button you would do an if statement checking if you met the NPC. If the flag is true, then your message will pop up. Also if you need help coding the battle engine part for encounters, let me know

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    43

    Re: Calling a button only after conditions have been met?

    Thanks Jacob. I have seen some of your very impressive combat engines like the world of warcraft combat system. I'm going to research flagging my npcs and the visible and not visible button, but after that is the combat section. I am sure I will have questions.

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    43

    Re: Calling a button only after conditions have been met?

    Ok, next part in this question.

    I've figured out how to change a button from invisible to visible by btnWhatever.Visible = True, after clicking on the button.

    This only works if both buttons are in the same Class. I want the first button in class 1 to trigger the code above and allow the button in class 2 to now be visible.

    I've tried playing with the public/private indicator of each button but that doesn't seem to be working. Can a button in one class trigger an event for a button in another class, so that it can become visible?

  7. #7
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: Calling a button only after conditions have been met?

    surely if you can identify a button you can set its properties

    use the fullname of the button

    like when a button is on form1 its called form1.button

    here to talk

  8. #8

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    43

    Re: Calling a button only after conditions have been met?

    Quote Originally Posted by incidentals View Post
    surely if you can identify a button you can set its properties

    use the fullname of the button

    like when a button is on form1 its called form1.button
    I do know how to change the properties of the buttons. What I'm confused on is if a button in one class can change the property of invisible to visible of another button in another class?

  9. #9
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Calling a button only after conditions have been met?

    It's possible to change the properties of a Button from one class to another, But are you using the 2 classes are 2 separate form windows? Or are you using a standard class to change the property of a button through a form class? Heres a standard class changing the property of a button in a form class:

    vb.net Code:
    1. 'Class1.vb file
    2. '-------------------------------
    3. Option Explicit On
    4. Option Strict On
    5.  
    6. Public Class Class1
    7.  
    8.     Private Flag As Boolean = True
    9.  
    10.     Public Sub Change_Visible()
    11.  
    12.         If Flag = False Then
    13.             Flag = True
    14.             Form1.Button1.Visible = True
    15.         Else
    16.             Flag = False
    17.             Form1.Button1.Visible = False
    18.         End If
    19.  
    20.     End Sub
    21.  
    22. End Class
    23.  
    24. 'Form1.vb file
    25. '---------------------------------------------
    26. Option Explicit On
    27. Option Strict On
    28.  
    29. Public Class Form1
    30.  
    31.     Private Test As New Class1
    32.  
    33.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    34.  
    35.         Test.Change_Visible()
    36.  
    37.     End Sub
    38.  
    39. End Class

    2 separate forms as another way:

    vb Code:
    1. 'Form2.vb
    2. '--------------------------
    3. Option Explicit On
    4. Option Strict On
    5.  
    6. Public Class Form2
    7.  
    8.     Private Flag As Boolean = True
    9.  
    10.     Public Sub Change_Visible()
    11.  
    12.         If Flag = False Then
    13.             Flag = True
    14.             Form1.Button1.Visible = True
    15.         Else
    16.             Flag = False
    17.             Form1.Button1.Visible = False
    18.         End If
    19.  
    20.     End Sub
    21.  
    22.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    23.  
    24.         Change_Visible()
    25.  
    26.     End Sub
    27.  
    28.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    29.         Me.Focus()
    30.     End Sub
    31. End Class
    32.  
    33. 'Form1.vb
    34. '-------------------------------------
    35. Option Explicit On
    36. Option Strict On
    37.  
    38. Public Class Form1
    39.  
    40.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    41.         Form2.Show()
    42.     End Sub
    43. End Class

  10. #10

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    43

    Re: Calling a button only after conditions have been met?

    Thanks Jacob. The second code I think would work. I was using two buttons each in different classes and in different Forms.
    BTW I just finished the design logic for my combat class, so I suspect I might be asking you for a hand if my design doesn't work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width