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 / Simple variable/rnd conflict

Author
Message
gr1n
21
Years of Service
User Offline
Joined: 24th Apr 2004
Location:
Posted: 24th Apr 2004 23:42
I just KNOW that I'm going to kick myself for not being able to find this, but for some reason, there's an rnd command in this code (closer to the end) that ALWAYS comes up 0. It's the variable 'zsroll.' The actual call for the rnd is:

zsroll = rnd(zs)

I even added this to the code, as you can see:
If zsroll < 1 then zsroll = 1

But it still comes up as zero.

I wrote a simple little five line thing, like

-----------------
a = 5

do
print rnd(a)
cls
loop
-----------------

And it worked fine, so I really don't know what I'm doing wrong. I'm sure it's just a typo that I've failed to grab while coding in the middle of a catatonic 3 a.m. stupor, but regardless, any help will be greatly appreciated. Thank you, everyone.

I will eat your flesh.
medwayman
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: uk
Posted: 25th Apr 2004 09:14 Edited at: 25th Apr 2004 09:45
You define Zhit$ at the start of you programme when zsroll=0 so you will always get 0 even though zsroll is returning a random value in your subroutine.

Rather than having:
zhit$ = "You attack the human for "+str$(zsroll)+" damage!"
at the start of your code.

Try:
center text 320,160,"You attack the human for "+str$(zsroll)+" damage!"
in your Attack and defend subroutine.

EDIT:
Use:
randomise timer()
at the start of your code to ensure you get a different set of random numbers every time your programme runs.

For a random number between 1 and 5 you did this:
zs=5
zsroll=rnd(zs)
if zsroll < 1 then zsroll = 1

This will do the same:
Zs=4
Zsroll=rnd(zs)+1


EDIT2:
I missed this:
Quote: "I even added this to the code, as you can see:
If zsroll < 1 then zsroll = 1

But it still comes up as zero."



Sorry I just woke up in my comp chair with a stiff neck. I really must go to bed sometimes. Im told beds are quite comfortable.

Based on Amiga PD game Squigs. Early shots: http://www.custardsoft.pwp.blueyonder.co.uk/images/03.png

gh0u1
21
Years of Service
User Offline
Joined: 24th Apr 2004
Location:
Posted: 25th Apr 2004 12:24
Oooh, thank you. Didn't realize that strings set things in stone.

You can sleep when you're dead.

Thank you very much for the help; now I can actually continue.
medwayman
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: uk
Posted: 25th Apr 2004 13:05


Quote: "
You can sleep when you're dead. "


lol

A couple of weeks ago I fell asleep with my leg resting on the corner of my desk. I spent most of that day limping as a result.

Based on Amiga PD game Squigs. Early shots: http://www.custardsoft.pwp.blueyonder.co.uk/images/03.png

gh0u1
21
Years of Service
User Offline
Joined: 24th Apr 2004
Location:
Posted: 25th Apr 2004 19:31
Ugh. Now I'm getting a nesting error. I swear, either I'm the most impulsive/codependant progger ever, or DB just likes to make problems for me. My guess would be the former. If anyone could give this a readthrough, I'd be very thankful... I think I'm just missing an endif or I have a 'return' in the wrong place (I was told once that 'gosubs' are a trap... maybe that was something else... can't remember...). There are some small codes that might seem placed sporatically; this is just because I was trying to identify the problem.

And I totally fell asleep right next to the comp. I'm having trouble finding my lower body.
gh0u1
21
Years of Service
User Offline
Joined: 24th Apr 2004
Location:
Posted: 26th Apr 2004 04:27
Bump

Just wondering if anyone was there...
sponge008
21
Years of Service
User Offline
Joined: 8th Feb 2004
Location: MA, USA
Posted: 28th Apr 2004 01:57
In this code:


There is a missing endif.

Login to post a reply

Server time is: 2025-05-23 16:11:57
Your offset time is: 2025-05-23 16:11:57