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 / Variable(?) After Center Text does not work.

Author
Message
Dark Frager
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: The Void.
Posted: 17th May 2012 18:37 Edited at: 17th May 2012 18:39
Hi,

I just began coding in DBPro yesterday and started using TDK's tutorials.

I have began working on a small 2D RPG project, however I am having trouble with variables (I think that's what this is called)

My problem is this:

I am trying to set a health value (so Health: 100) but entering it in the editor like this

if charactertype# = 1 then center text 400,300,"Health: ";Health#

gives a syntax error.

I've tried to the hardest of my ability but I am not able to work this problem out.

Here is the rest of my code:


If anyone could help me that would be greatly appreciated.

Thanks!

Edit: Just fyi,


is where the problem is. The values have been replaced with text as a placeholder.

Fruitella's a badman sweet, do you get me?
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 17th May 2012 19:07
Quote: ""Health: ";Health#"


I believe should be...

Quote: ""Health: ",Health#"


Dark Frager
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: The Void.
Posted: 17th May 2012 19:10
Thanks for the response.

But it still gives a syntax error

Fruitella's a badman sweet, do you get me?
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 17th May 2012 19:11 Edited at: 17th May 2012 19:14
You need to use str$(YourVariable) to display it on the screen, like this:



It is worth mentioning that floats (variables that have the # sign after the name) are typically used when higher precision is needed (3D location in space for example, where you have a decimal point). If the CharacterType, health, armour and energy values are always going to be integers, then I would suggest you use an integer instead of a float.

Another thought is maybe you should choose something relatively easy for your first project. Typically a game of pong is challenging enough to create, yet is doable as a first game. An RPG seems like a lot to take on at first.

EDIT: Also, you could write it a little more efficiently using an if / endif:


Anyway, good luck to you.

So many games to code.......so little time.

Dark Frager
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: The Void.
Posted: 17th May 2012 19:22
Thanks for your response.

That worked.

And I know that an RPG is a bit too much for a beginner, but it's always worth giving it a try.

Fruitella's a badman sweet, do you get me?
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 17th May 2012 19:31
thanks LBFN you are always fantastic not seen you for a couple of weeks have you been busy?

Dark Frager

still begin with something small like a platformer or break down the various elements of your RPG and make small demos to get more experience before putting it all together

thats my approach at present. [I too have begun creating an RPG still in written phase right now... concept art is next... bought a graphics tablet for that phase]

LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 17th May 2012 19:57
Hey Mr V, thanks much. Busy as always, hope things are going great for you.

Dark Frager, the reason I suggest an easier game is that programming is a skill that needs to be developed. One thing to guard against is discouragement. It is possible to get discouraged when you keep trying different things and they don't work right or at all, or you have to keep asking for information and it doesn't come as quickly as you want or at all. On the other end, there is a good feeling of accomplishment when you are able to complete a project. You then move onto something else that presents new challenges and you learn new things. You build confidence in your skills and it makes for an enjoyable pastime.

So many games to code.......so little time.

MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 17th May 2012 20:05
LBFN doing good too busy as well but this forum is so addictive

Dark Frager yeah also, sometimes procrastination comes into play...

I want to also add, if you are making an RPG, make sure you take walks in a nature reserve or local park which has lots of trees for massive amounts of inspiration!

[its what I have been doing this week... SO MUCH INFORMATION!!!... oh and textures ^^]

Dark Frager
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: The Void.
Posted: 19th May 2012 18:35
Since I don't want to litter the board with new threads, I'll just ask the question in this thread .

So, I've learned how to load sprites into my games and etc... everything is fine, except for the fact that when I load a sprite it removes any text that I put in with the center text command. I've looked this up and someone mentioned "bitmap fonts" which then I also looked up, but I didn't find anything useful/down to the point.
Can anyone point me in the right direction or suggest what to do?

Thanks for the help!

Fruitella's a badman sweet, do you get me?
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 19th May 2012 20:38
I think the text problem is because once you use sprites, you invoke the 3D Backdrop. Therefore, your TEXT command must be repeated in the loop. Example:


Dark Frager
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: The Void.
Posted: 20th May 2012 00:18 Edited at: 20th May 2012 00:19
Thanks for your response.

Your code works fine, but in my case it does not work wherever I place it. Could you suggest what do or where the lines should be placed? Thanks!

Here is my code:



Fruitella's a badman sweet, do you get me?
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 20th May 2012 08:36
In your case I suggest rendering your text to a bitmap and spriting it. It it were just a few lines I'd say WHILE (counter): TEXT etc: ENDWHILE but you've multiple instances of TEXT: WAIT KEY so take my first option - it's easier. The reason WAIT KEY doesn't work is due to the lack of refreshing (program is suspended in a small loop the checks for inputs). Hope this clarifies.

Dark Frager
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: The Void.
Posted: 20th May 2012 10:24
Thanks for your response.

I'll try your suggestion and I know that Wait Key does not work but I kept it in there for some reason.

Fruitella's a badman sweet, do you get me?
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 20th May 2012 14:37
I don't have your media, so I cannot run this, but here is some suggested code for you. You can program it more efficiently. I haven't done everything for you, but hopefully, you can learn from it. Setting the COLORKEY continually in the main do - loop is a waste of time, you should set it initially in the code. I don't know why you would set sprite 1's priority to 1, as either sprite 1 or 2 will be on the screen, so it is unnecessary.




There's more I could do to help, but I simply don't have the time. I do hope this is helpful.

So many games to code.......so little time.

Dark Frager
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: The Void.
Posted: 20th May 2012 16:52 Edited at: 20th May 2012 18:11
Wow! Thanks for that, LBFN. I can't believe you actually put your time into sorting all this out for me. BIG thank you!

Quote: " I don't know why you would set sprite 1's priority to 1, as either sprite 1 or 2 will be on the screen, so it is unnecessary. "


Thats because, when I load the "GrassBackground1.bmp" it covers the whole screen, and when the character sprite is loaded, it is covered by the Grass background so I had to set it's priority.

Thanks for your help!!!

EDIT: I still can't figure out the text issue, I'll keep trying with what I can. If need be, I can supply the files for the game, or otherwise I'll just look into bitmap fonts since that seems to be the main solution.

Fruitella's a badman sweet, do you get me?
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 20th May 2012 19:47
Here's some stuff that may help with the text thing - Or rather an example of what I explained (a little vaguely) in my earlier post. This example showcases some stuff you can do to overcome your text woes. Didn't have time to make a lot of comments, hopefully there are enough to follow it.


Dark Frager
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: The Void.
Posted: 20th May 2012 20:00 Edited at: 20th May 2012 20:31
Awesome! That worked. Thank you for that

Edit: Messed around with the code for a bit to suit my needs and it still works fine. Big thanks to everyone to helped!

Edit2: Another small question: If I use inc or dec to decrease the values (in my case:
) will I have to update the bitmap manually (as in getting the image everytime the value is changed) or does it change on screen itself?

Fruitella's a badman sweet, do you get me?
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 20th May 2012 20:43
Quote: "If I use inc or dec to decrease the values will I have to update the bitmap manually"

Unfortunately yes. In such a case you may suffer some performance loss. These situations may require the non-bitmap version (the plain TEXT method) unless you're using a tiny area as GET IMAGE slows down the program significantly. You'll have to play around with that and just see what the performance costs are (as per your needs).

Dark Frager
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: The Void.
Posted: 20th May 2012 21:01
Ok thanks!

Fruitella's a badman sweet, do you get me?
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 21st May 2012 01:09
Quote: " I don't know why you would set sprite 1's priority to 1, as either sprite 1 or 2 will be on the screen, so it is unnecessary. "

Quote: "Thats because, when I load the "GrassBackground1.bmp" it covers the whole screen, and when the character sprite is loaded, it is covered by the Grass background so I had to set it's priority."


My bad; I should have said that you should set sprite 1's priority before the main DO - LOOP. You don't need to continually set it like you are.

So, have you solved printing the text issue then?

So many games to code.......so little time.

Dark Frager
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: The Void.
Posted: 21st May 2012 18:54
Yes I have, nonZero's post a few posts up helped me with this.

Fruitella's a badman sweet, do you get me?

Login to post a reply

Server time is: 2024-11-23 20:24:56
Your offset time is: 2024-11-23 20:24:56