|
-
Dec 27th, 2011, 03:59 PM
#1
Thread Starter
Member
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?
-
Dec 27th, 2011, 04:03 PM
#2
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
-
Dec 27th, 2011, 04:13 PM
#3
Thread Starter
Member
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!!
-
Dec 27th, 2011, 05:28 PM
#4
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:
Public Structure NPC_Type Dim X As Integer 'X Position of NPC on map Dim Y As Integer 'Y Position of NPC on map Dim Met_Flag As Boolean End Structure 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
-
Dec 27th, 2011, 09:02 PM
#5
Thread Starter
Member
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.
-
Dec 28th, 2011, 01:43 PM
#6
Thread Starter
Member
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?
-
Jan 2nd, 2012, 01:03 PM
#7
Frenzied Member
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
-
Jan 2nd, 2012, 01:47 PM
#8
Thread Starter
Member
Re: Calling a button only after conditions have been met?
 Originally Posted by incidentals
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?
-
Jan 2nd, 2012, 02:09 PM
#9
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:
'Class1.vb file '------------------------------- Option Explicit On Option Strict On Public Class Class1 Private Flag As Boolean = True Public Sub Change_Visible() If Flag = False Then Flag = True Form1.Button1.Visible = True Else Flag = False Form1.Button1.Visible = False End If End Sub End Class 'Form1.vb file '--------------------------------------------- Option Explicit On Option Strict On Public Class Form1 Private Test As New Class1 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Test.Change_Visible() End Sub End Class
2 separate forms as another way:
vb Code:
'Form2.vb '-------------------------- Option Explicit On Option Strict On Public Class Form2 Private Flag As Boolean = True Public Sub Change_Visible() If Flag = False Then Flag = True Form1.Button1.Visible = True Else Flag = False Form1.Button1.Visible = False End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Change_Visible() End Sub Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Focus() End Sub End Class 'Form1.vb '------------------------------------- Option Explicit On Option Strict On Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Form2.Show() End Sub End Class
-
Jan 2nd, 2012, 02:17 PM
#10
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|