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.

DarkBASIC Discussion / Storing lifes?

Author
Message
Yodaman Jer
User Banned
Posted: 24th Feb 2008 00:42
Hey all, I searched and searched but could only find the answer to this question in the DBPro boards or FPSC, not the DBC boards.

My question is how do you store three lives and when the player dies, drops by 1?

Yes, yes, I realize it requires variables, I'm just not sure how to implement the code and make it work.

If anyone can tell me a solution I would greatly appreciate it!!

Yodaman Jer


Thanks BigAdd!!
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 24th Feb 2008 00:50 Edited at: 24th Feb 2008 00:53
well, the way i do it is like this...



or if you used arrays...

Yodaman Jer
User Banned
Posted: 24th Feb 2008 00:56
I have to say using arrays look like a lot less work for that.

"no offense to sonic.." That cracked me up!!
Thanks!


Thanks BigAdd!!
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 24th Feb 2008 00:57 Edited at: 24th Feb 2008 00:59
Quote: "I have to say using arrays look like a lot less work for that. "

Yes.

Your Welcome.
LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 24th Feb 2008 01:12
A minor point, but worth mentioning: float variables should only be used when you need more precision than what integers give. In DD's first example, 'lives#', a float, is used. Since you only need integer precision, 'lives' would work fine and should be used.

In the second example, it goes without saying that you could also simply code:


LBFN
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 24th Feb 2008 01:16
Quote: "A minor point, but worth mentioning"

A very good point,indeed. I didn't think about that..
Yodaman Jer
User Banned
Posted: 24th Feb 2008 01:23
Quote: "In the second example, it goes without saying that you could also simply code:
+ Code Snippet

lives(1)=lives(1)-1"


Oh well, that'd be even better! (Sorry DD)

Would that go in or out of the program loop?


Thanks BigAdd!!
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 24th Feb 2008 01:25
its okay.
withn the loop enclosed in the if endif statement.
Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 24th Feb 2008 01:57
let me have a go at this

it's a bit messy, but if you delete all the comments, it's a pretty tidy code.

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Feb 2008 04:49 Edited at: 24th Feb 2008 06:03
Quote: "I have to say using arrays look like a lot less work for that."

You don't really need to use an array here, unless you have more than one entity with numerous lives, or maybe you have some sort of powerup that randomly increases a stat e.g.

The power-up example doesn't require the use of an array but it would mean less code.

I feel like a bit of coding so I'll write a little game to show you how I'd do it.
[edit]
no I don't I'm tired and my example got complicated because I started making an actual game!

LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 24th Feb 2008 05:07
OBese87
Nice example, but it should be RndStat = rnd(3) + 1, because you want a number between 1 and 4.

An array would be advantageous if you intend to have the routine that decreases lives in a function.

LBFN
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Feb 2008 05:39
Quote: "Nice example, but it should be RndStat = rnd(3) + 1, because you want a number between 1 and 4.

An array would be advantageous if you intend to have the routine that decreases lives in a function."

Good points, no globals in DBC
I wish we had globals and constants, would make life so much easier

Yodaman Jer
User Banned
Posted: 25th Feb 2008 23:42
@Link 102:
Thank you, your code has shown me the way to use variables in a practical efficient way. Thank you!


Thanks BigAdd!!
Yodaman Jer
User Banned
Posted: 26th Feb 2008 00:08
I have a problem: All the life and helath variables work like a charm but I can't get the text that tells you the life information to say. It quickly scrolls down, never to be seen again!!
Here's my code:


Everything works except that one little problem. Can anyone tell me how to fix it?

Thanks in advance!!

Yodaman Jer


Thanks BigAdd!!
LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 26th Feb 2008 01:07
To address the life info text problem, all you need to do is use 'set cursor 0,0' in order to get them to print at the top left of the screen. I would suggest using:


Please do the following:
1. Always use a RETURN command at the end of a subroutine. You can make a do - loop in your subroutines and just use 'if spacekey()=1 then exit'. This will exit the do - loop cleanly and with a return command following, it will go back to the main program properly.
2. Indent your code. Most people will not help you if they have to sort through your code. Here is how I would indent your code (I made a couple of edits too)

3. Things that don't need to be repeated in every do - loop iteration should not be included in the do - loop. In your code, you set the text font and size each iteration and this will slow your program down considerably. You probably wouldn't notice it with this code, but someday you may code something that it will matter. Anyway, it is good programming practice to only have what you need inside the do - loop.

Hope this helps,

LB
Yodaman Jer
User Banned
Posted: 26th Feb 2008 16:21 Edited at: 26th Feb 2008 17:06
Thanks LBFN!! I'll be sure to indent my code next time too.

EDIT:
I've now used all of this information to make my game collect jewels and keep track of how many it has! The limit is 50, and once you have 50


SO I would like to thank everyone who has helped me out on this. You have all taught me a lot over the last couple of days, and I personally thank you all. Well, kinda personally, anyway...

Yodaman Jer


Thanks BigAdd!!
LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 27th Feb 2008 00:16
You're welcome; glad to help.

You know, the ever-resourceful TDK wrote a program to tidy up and indent your code for you. You'll find it here:
http://forum.thegamecreators.com/?m=forum_view&t=104344&b=5

Best,

LB

Login to post a reply

Server time is: 2025-06-05 18:57:42
Your offset time is: 2025-06-05 18:57:42