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 / My health regeneration code is stopping my gameplay section and goes on an infinite loop. + Dissapearing text

Author
Message
My games are free
15
Years of Service
User Offline
Joined: 28th Sep 2009
Location: Under your Bed
Posted: 19th Feb 2012 23:52
I cant explain it very good but, I have the code for the first level (or at least start for it) and i made an health regenerate thing for my game. the problem is that when i run the code, it first begins as it should, but then it goes to the health regeneration code. what im asking is to get the HPReg. code to be "invisible" throughout the game it only should regenerate health. And i have.
code for the 1st map


and heres my health reg. code


it never gets back to my game

and the other problem is that when i add for example a cube in my map
every text disappears and is not to be seen

The Weeping Corpse
13
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
Posted: 20th Feb 2012 06:17
goto inchealth

should be

gosub inchealth

and the value of nohealth needs to be specified. so,

health = 100
maxhealth = 100
nohealth = 0
My games are free
15
Years of Service
User Offline
Joined: 28th Sep 2009
Location: Under your Bed
Posted: 20th Feb 2012 08:07 Edited at: 20th Feb 2012 08:12
i had it at first as gosub inchealth and i actually had exactly "nohealth = 0" in my previous code, ill try it again, thanks more ideas are accepted
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 20th Feb 2012 11:25
I think you may need to restructure your program. A lot of programmers adopt the practice of having a main loop, typically a do-loop and then have most events inside that loop.

E.g



Quote: "and the other problem is that when i add for example a cube in my map
every text disappears and is not to be seen"

The TEXT command may be a better choice.



My games are free
15
Years of Service
User Offline
Joined: 28th Sep 2009
Location: Under your Bed
Posted: 20th Feb 2012 14:19
Hodgey: your code was almost perfect, but when i run it, it starts counting the numbers but the system starts putting numbers on top of each other like if theres a -10 from the starting health, it goes 90-91-92 and all numbers go above each other. i made a slight change to make it go normally.


another problem comes in, now i cant see the "Health 100/100" text until health is under 100
and along that, i am back to the infinite loop of health regen.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 20th Feb 2012 20:28
Think your best placing text at something other than 0,0... try 30,30

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 20th Feb 2012 20:50
Quote: "it starts counting the numbers but the system starts putting numbers on top of each other"

The text command is independent of the print command and so overlapping text is easy to come across. Simply change the coordinates used each time you use TEXT.

Quote: "another problem comes in, now i cant see the "Health 100/100" text until health is under 100"

Try moving the text line from the sub routine to inside the do-loop.

My games are free
15
Years of Service
User Offline
Joined: 28th Sep 2009
Location: Under your Bed
Posted: 20th Feb 2012 21:31 Edited at: 20th Feb 2012 22:16
Hodgey:
Quote: "Quote: "it starts counting the numbers but the system starts putting numbers on top of each other"
The text command is independent of the print command and so overlapping text is easy to come across. Simply change the coordinates used each time you use TEXT."

i told this in previous post but i already got it work by adding a cls in middle of it. And i meant that when it regenerates health it overlaps previous numbers.

Quote: "Quote: "another problem comes in, now i cant see the "Health 100/100" text until health is under 100"
Try moving the text line from the sub routine to inside the do-loop."


This worked, thanks man, but im still in the inf. loop

EDIT: almost forgot this, my fix on your code doesnt work as it clears everything from screen...
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 21st Feb 2012 09:51 Edited at: 21st Feb 2012 09:54
I'm not supposed to be here, I have a project to do (and an angry friend if he catches me slacking). I promised I'd just lurk to stay abreast of things until I was finished my project and the stuff I'm helping my mate with yet here I am...
Oh well, couldn't resist...

1) Hodgey's code is perfect. There are no "errors". It's simply not being implemented correctly.
2) Your program gets stuck in a loop because of structuring.

1). Use Hodgey's code but remove all CLS statements from your code and replace all PRINT statements with TEXT. Now use the following code at startup, after setting up your display:

Before you say "it's all gone black", see number 2

2). Make every call [sub/function] a dynamic one. DO..LOOP in most cases should be avoided in functions/subs. Example:

Dynamic coding makes life easier once the habit is formed. Using 3D screen mode even for text-based things actually BETTER because you'll end up using less statements, especially where PRINT and CLS are concerned so your code becomes neater and more compact and, ultimately, easier for you and the machine to handle.

Hopefully this clarifies it all. Good luck.

My games are free
15
Years of Service
User Offline
Joined: 28th Sep 2009
Location: Under your Bed
Posted: 21st Feb 2012 13:52 Edited at: 21st Feb 2012 13:54
nonzero:
Yea, i just read a subject on program structure and layout (TDKs tutorials) a very big thanks on his work, and to Hodgey i must say sorry for saying your code bad instantly i really appreciate everyones help. Ill try your code now nonZero. And really big thanks to you for helping me even when you have a project (+ an angry friend, i know the feeling) sorry for interrupting your work
My games are free
15
Years of Service
User Offline
Joined: 28th Sep 2009
Location: Under your Bed
Posted: 21st Feb 2012 17:53 Edited at: 23rd Feb 2012 21:40
It still goes overlapping the prev. numbers...

EDIT: sorry, it was my own fail
EDIT: I got it working, thanks everyone for your support. Heres the Code, if you have problems with it, tell me

Login to post a reply

Server time is: 2024-11-22 05:51:28
Your offset time is: 2024-11-22 05:51:28