Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / RPG health + magic points bar prob

Author
Message
Kelz
19
Years of Service
User Offline
Joined: 7th Apr 2005
Location: At the computer
Posted: 13th Apr 2005 06:14
I'm programming an RPG with someone and in the battle system we're having a small problem.
We set the down key to decrease the hp and mp by one, each time it's pressed and the upkey to increase it. the health bar works fine but the magic bar goes crazy and decreases very rapidly and it goes off the end of the bar when increased again. Once the mp bar was taken out the health bar did it too. I can't post the code cos it's not mine and has a function asigned to it and so on, does anyone know what kind of problem we have or have an example of code to work from? DB or DBPro i don't mind
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 13th Apr 2005 10:55
Hard to say without seeing code.

Problem: DBPro doesn't keep track of the object's original size.
Solution: I start with an object size one and expand it appropriately for the functions its used in, then shrink it again back to one.
Alternate: Delete the object, recreate it, and scale it to the appropriate size.
Alternate: Use Globals to track object sizes; original size, and current size.

Offhand, it sounds like you might be having a problem similar to that I just described, or something with variables handling the size change routines.



"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
Spaceman Spiff
20
Years of Service
User Offline
Joined: 27th Jan 2004
Location: Smacking my head on your keyboard.
Posted: 13th Apr 2005 14:04 Edited at: 13th Apr 2005 14:05
Are these numrical values, or are the bars graphical objects like sprites or 3D boxes. It would help if you could give out a bit more information. If you can't put the code on here why can you use it?

Sorry but without something to look at, I don't think many people will be able to help.

Edited for spelling

Smile, it confuses people.
Soy Cocktail
20
Years of Service
User Offline
Joined: 23rd Dec 2003
Location:
Posted: 13th Apr 2005 17:36
It seems like a common mistake where it is an if statement in a loop. The loop is ran several times in a second (depends on the sync rate). If, for example, you do:
do
if upkey()=1
inc health#
endif
loop
When you lightly tap the upkey it will increase the variable health many times, and not just once per keypress. The reason why the upkey doesn't rapidly increase has to do with the way you setup your if statements. When you remove the downkey part it makes the upkey part run rapidly since it isin't prevented by the downkey section of code.

To fix this I normally use a variable to store if the key is pressed or not. For example I would make pressed_up as boolean and use it to store the state of the key. when it first detects that the upkey is pressed it makes pressed_up=1. The code only runs if upkey()=1 and pressed_up=0. This means that it will only run once. You want it to reset the pressed_up variable when you release the upkey. to do this simply add:
if upkey()=0 and pressed_upkey=1 then pressed_upkey=0

This is only just a guess though. As RiiDii said "[It's] Hard to say without seeing code." Code does help when asking for help. You have to help us help you. We are not out to steal your game, but to help.

When life hands you lemons go buy some oranges to make orange juice, and stop expecting everything to be given to you.
PowerFang
20
Years of Service
User Offline
Joined: 6th Feb 2004
Location: Australia (But currently in the USA)
Posted: 13th Apr 2005 19:56 Edited at: 13th Apr 2005 19:57
As Soy Cocktail said, thats one of the common reasons for the bar behaving that way.

The other one is if you do it like this:

if upkey() = 1 then HealthChange = +1

then somewhere else in the loop you have:

Health = Health + HealthChange

Now if you dont reset HealthChange when no key is pressed, it will constantly increase/decrease every loop.
Kelz
19
Years of Service
User Offline
Joined: 7th Apr 2005
Location: At the computer
Posted: 14th Apr 2005 03:04
I'm pretty much new to programming and my boyfriend "Xzi" is doing most of it. the code is on his pc and i don't understand it that much, mostly because it includes a function.
We're using a sprite with a percantage value as the hp and mp.
Thanks for the help so far
Xzi
20
Years of Service
User Offline
Joined: 3rd Jan 2004
Location: England!
Posted: 14th Apr 2005 03:12
The code is mine, and I'm very happy that Kelz didn't post my code without permission.
Basically I've assigned an increment to the up and down arrows respectively, so when you press up health goes up, this is to test it.
When I was testing it I found out that the mp bar, when being increased, goes further than it should, i.e the percentage made for the bar goes above 100%. But the actaul percentage number is accurate.
This is my code:

This is the function


:: 'Xzi' is pronounced 'Zee' due to the wonders of the English Language ::
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 14th Apr 2005 06:09
I'm looking it through. One suggestion I would make is to use UDT's instead of multi-dimensional arrays (in this case). It would be alot easier to read and you'd be less likely to make a coding error.

Example:


I'll keep looking through your code though to see what's going on.

"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
Xzi
20
Years of Service
User Offline
Joined: 3rd Jan 2004
Location: England!
Posted: 14th Apr 2005 07:32
Right I understood how multi-dimensional arrays worked, so I used them lol. With the example you've given me would how would I go about calling the hp information for the first character from the array?
I'm geussing that Char(20) means that there are 20 characters, within the array right.
Apart from working out how to get each individual piece of infromation, I understand that, and will most probably replace our existing arrays thanks!

:: 'Xzi' is pronounced 'Zee' due to the wonders of the English Language ::
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 14th Apr 2005 07:56
You would use it like this:
Char(1).hp=25
Char(1).mp=30

It looks like you've found a DBPro bug!
Simply add a ",1" to the end of your get image commands and it should work. I have to run right now, but I'll cover more of what I found later.

"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 14th Apr 2005 11:52
Basically what I discovered was that the Get Image command was the culprit (as you can see by the earlier post). And I didn't just guess at that solution and get it right off. I worked my way through all the commands that could have affected the output the way it did. Sprites, variables, If/Then's (got rid of these completely to test). I switched them around, altered them, tried different methods. Last but not least was the Get Image Command. I validated that the variables plugging into the commands were acurate by printing them after the Get Image command. Then I tried switching them around. Sure enough, the later image (higher number) always had the bug - regardless of the variables and regardless of the sprite. That's when I tried the ",1" solution - and it worked perfectly.

Try this test code:



The first 2 sprites are using ",0" and the 2nd two use ",1".
Now I don't understand why one of your images worked and the other didn't since they both had nothing (basically ",0"). That's the real bug. This issue in this test code might just be the way things work - I don't know.

"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
Xzi
20
Years of Service
User Offline
Joined: 3rd Jan 2004
Location: England!
Posted: 15th Apr 2005 05:21
Excellent, this problem has been bothering me for ages! This just shows how great these forums really are! Thanks.

I should have geussed how the array worked, because that's how it's done in javascript, I'm surprised I didn't make an educated geuss, thanks for that too!

:: 'Xzi' is pronounced 'Zee' due to the wonders of the English Language ::
Kelz
19
Years of Service
User Offline
Joined: 7th Apr 2005
Location: At the computer
Posted: 23rd Apr 2005 19:19
I looked through the UDT(?) code and I'm still a little confused i tried to run it in a program in DBPro and it says it doesn't understand the term 'coordinates' also when you've done the dim char(20) then do you put your characters in an array under this? and what does the as characters mean? sorry i just want to fully understand this so i can use it properly
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 24th Apr 2005 01:44 Edited at: 24th Apr 2005 01:50
Quote: "DBPro and it says it doesn't understand the term 'coordinates'"

My bad. I typo'd the first spelling of "coordinates" - got the 'a' and 'n' switched.
Here:


Quote: "when you've done the dim char(20) then do you put your characters in an array under this?"

Exactly. Coding 20 different variables (for 20 characters - for example) for each for the character stats in an rpg would mean you would have to type 20 x N variables (N=number of stats) each time you needed them in your code. Not efficient coding at all.
Examples:



A multidimensional array (i.e. Dim char(20,7) for 20 characters with 7 stats each) is sometimes even more efficient, but you reduce code readability.

Quote: "and what does the as characters mean?"

That's telling DB to use my User Defines Type "Characters" as the variable type for the array. Here's a sample code I use quite often.



In the sample, I used a UDT to define a Global variable, not an Array. The concept is exactly the same. The only difference is how you type the variable. An Array would look like: MyArray(i).UDT1 or Char(i).pos.x
Hope this explains some of what's going on.

Edit: In the code snippets section, I posted a thread called "Guess if this will work", which was about User Defined Types. I was learning a little more each time about User Defined Types as we went along. Take a look - I think you will find it interesting and useful.

"Droids don't rip your arms off when they lose." -H. Solo
REALITY II

Login to post a reply

Server time is: 2024-09-23 19:36:46
Your offset time is: 2024-09-23 19:36:46