For anyone that knows Visual Basics
ok here is my problem. I have a exp system working so when I get exp
it adds it to a bank to store the total number of exp. Here is the code:
Public Sub Add(X As Integer, Y As Integer)
Dim Z
Z = X + Y
frmmain.Exp = Str(Z)
X = expgained.Caption
Y = frmmain.Exp.Caption
End Sub
Private Sub Command1_Click()
Add expgained, frmmain.Exp
The problem is when I get to 500 exp I want my level to go to 2. Here
is the code for that:
If frmmain.Exp.Caption >= "500" And frmmain.lvl.Caption = 1 Then
frmmain.lvl.Caption = "2"
MsgBox "you gained a level!"
End If
Now the problem is when I get more then 500 exp it doesent change
the number. Someone please help. This is the one thing I need to
finish the game. I got everything down but the level system.
You have to becareful the way you are testing for the 500. First, I see you didnt declare what Z was, I hope you do that in your real program, that is bad memory practice. Second, when you are testing for it you are using the ascii value because of the quotes around the 500. Use the val() function , your code should look like this:
If val(frmmain.Exp.Caption) >= 500 And
val(frmmain.lvl.Caption) = 1 Then
''do what ever here
If val(frmmain.Exp.Caption) >= 500 And
val(frmmain.lvl.Caption) = 1 Then
''do what ever here
Thanks. You are actuially helpful. This is my first attemp at a game and the code is really crappy. I am just learning C++ now and Im gonna make all my games on that. Can you just tell me one thing, What do I declare z as? Do I declare z as the label where I want the addition answer?
First for the level entering you should do something like this
example:
dim exp as long ''declaration of experience
dim level as integer ''decleration of level
dim lvlimit(2 to 3) as long ''here we declare the limit you want to enter a level here the maximum level is 3
''assinging values
exp= 0
level =1
lvlimit(2) = 500
lvlimit(3)= 1000
if exp >= lvlimit(playerlevel+1) then
level = level + 1
form.lbllevel = level
end if
secondly for the experience gaining
here is an example function not sub
private function add(x as long,y as long)
add = x + y
end function
example:
dim exp as long ''declaration of experience
dim level as integer ''decleration of level
dim lvlimit(2 to 3) as long ''here we declare the limit you want to enter a level here the maximum level is 3
''assinging values
exp= 0
level =1
lvlimit(2) = 500
lvlimit(3)= 1000
if exp >= lvlimit(playerlevel+1) then
level = level + 1
form.lbllevel = level
end if
secondly for the experience gaining
here is an example function not sub
private function add(x as long,y as long)
add = x + y
end function
sorry fot the previous there is a mistake
the good is this:
First for the level entering you should do something like this
example:
dim exp as long ''declaration of experience
dim level as integer ''decleration of level
dim lvlimit(2 to 3) as long ''here we declare the limit you want to enter a level here the maximum level is 3
''assinging values
exp= 0
level =1
lvlimit(2) = 500
lvlimit(3)= 1000
if exp >= lvlimit(level+1) then
level = level + 1
form.lbllevel = level
end if
secondly for the experience gaining
here is an example function not sub
private function add(x as long,y as long)
add = x + y
end function
you should not update the label values in a function but i your basic loop.
the good is this:
First for the level entering you should do something like this
example:
dim exp as long ''declaration of experience
dim level as integer ''decleration of level
dim lvlimit(2 to 3) as long ''here we declare the limit you want to enter a level here the maximum level is 3
''assinging values
exp= 0
level =1
lvlimit(2) = 500
lvlimit(3)= 1000
if exp >= lvlimit(level+1) then
level = level + 1
form.lbllevel = level
end if
secondly for the experience gaining
here is an example function not sub
private function add(x as long,y as long)
add = x + y
end function
you should not update the label values in a function but i your basic loop.
Oh, the hell is better than that ( joke . Don't declare any variable without a type in VisualBasic. It causes that the variable would be a very slow variant.
Declare z like this:
Dim z As Long 'For fixedpoint
or
Dim z As Single 'For floatpoint
Now you can easily handle "z".
'your code here
z = x + y 'x and y should be of the same type like z
If z >= 500 Then
'rest of code
In C you should declare the variables like this:
long z; //For fixedpoint
or
float z; //For floatpoint
PS: Never handle numerics with strings. As u see it can causes some problems.
PPS: I hope u've understood me, my english is bad, sorry.
[edited by - LEKstor on June 7, 2002 10:13:27 AM]
Declare z like this:
Dim z As Long 'For fixedpoint
or
Dim z As Single 'For floatpoint
Now you can easily handle "z".
'your code here
z = x + y 'x and y should be of the same type like z
If z >= 500 Then
'rest of code
In C you should declare the variables like this:
long z; //For fixedpoint
or
float z; //For floatpoint
PS: Never handle numerics with strings. As u see it can causes some problems.
PPS: I hope u've understood me, my english is bad, sorry.
[edited by - LEKstor on June 7, 2002 10:13:27 AM]
Just a bit of general advice to the original poster...
It''s generally a bad idea to use the variables that are part of controls for your internal game logic. For example, don''t store your character''s experience as part of the form. Instead, declare your own variables (DIM experience as Integer, for example), and when the variables change, update the form to get its values from your own variables. In other words, the GUI should read from your code, not your code reading from the GUI. (The only exception being to grab data from input boxes and so on.) The benefits of this are that your code needs fewer edits if you change the GUI, the logic works whether you have a GUI or not, your variables won''t get changed by some user event, and so on.
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]
It''s generally a bad idea to use the variables that are part of controls for your internal game logic. For example, don''t store your character''s experience as part of the form. Instead, declare your own variables (DIM experience as Integer, for example), and when the variables change, update the form to get its values from your own variables. In other words, the GUI should read from your code, not your code reading from the GUI. (The only exception being to grab data from input boxes and so on.) The benefits of this are that your code needs fewer edits if you change the GUI, the logic works whether you have a GUI or not, your variables won''t get changed by some user event, and so on.
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement