Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → RANDom Error
RANDom Error
2003-03-09, 1:13 AM #1
Hi!
What seems to be wrong with this code?
Code:
	while(1)
	{
		If(s==0)
		{
			i=rand()*6;
			If(i==0) { PlaySoundLocal(hubba1,1,0,0xC0);
			sleep(GetSoundLen(hubba1)); }
			If(i==1) { PlaySoundLocal(hubba2,1,0,0xC0);
			sleep(GetSoundLen(hubba2)); }
			If(i==2) { PlaySoundLocal(hubba3,1,0,0xC0);
			sleep(GetSoundLen(hubba3)); }
			If(i==3) { PlaySoundLocal(hubba4,1,0,0xC0);
			sleep(GetSoundLen(hubba4)); }
			If(i==4) { PlaySoundLocal(hubba1,1,0,0xC0);
			PlaySoundLocal(hubba4,1,0,0xC0);
			sleep(GetSoundLen(hubba4)); }
			If(i==5) { PlaySoundLocal(hubba2,1,0,0xC0);
			PlaySoundLocal(hubba3,1,0,0xC0);
			sleep(GetSoundLen(hubba2)); }
		}
		Else if(s==1)
		{
			PlaySoundLocal(rayman1,1,0,0xC0);
			sleep(GetSoundLen(rayman1)+1);
		}
		SetWallCel(name,s);
	}

i does not seem to become more than 0! I play and I always get hubba1 again and again!

/Edward
Edward's Cognative Hazards
2003-03-09, 4:41 AM #2
Is "i" a defined integer? Because if it's not, rand() pulls out a flex, and it will almost never be equal to a whole number.

------------------
His pot is blacker than his kettle!

Phoenix Swords
"And lo, let us open up into the holy book of Proxy2..." -genk
His pot is blacker than his kettle!
2003-03-09, 7:56 AM #3
i is int. And this has worked before! People have used it before!

/Edward
Edward's Cognative Hazards
2003-03-09, 8:19 AM #4
The Rand() bit looks ok, but Im more wary of that While loop than the rest. Put a printint(i); statement after the random assignment, see what its coming out to.

------------------
Createthingatpos(GBK, 0, '0 0 0', '0 0 0');
And when the moment is right, I'm gonna fly a kite.
2003-03-09, 9:43 AM #5
Well, I've added the Print, and I see the problem. The i is regestering the rand() but the IF:s aren't regestering the i.
Here's an update on the code:
Code:
while(1)
	{
		If(s==0)
		{
			i=rand()*6;
			printint(i);
			If(i==0) { PlaySoundLocal(hubba1,1,0,0xC0);
			sleep(GetSoundLen(hubba1)); }
			else If(i==1) { PlaySoundLocal(hubba2,1,0,0xC0);
			sleep(GetSoundLen(hubba2)); }
			else If(i==2) { PlaySoundLocal(hubba3,1,0,0xC0);
			sleep(GetSoundLen(hubba3)); }
			else If(i==3) { PlaySoundLocal(hubba4,1,0,0xC0);
			sleep(GetSoundLen(hubba4)); }
			else If(i==4) { PlaySoundLocal(hubba1,1,0,0xC0);
			PlaySoundLocal(hubba4,1,0,0xC0);
			sleep(GetSoundLen(hubba4)); }
			else If(i==5) { PlaySoundLocal(hubba2,1,0,0xC0);
			PlaySoundLocal(hubba3,1,0,0xC0);
			sleep(GetSoundLen(hubba2)); }
		}
		Else if(s==1)
		{
			PlaySoundLocal(rayman1,1,0,0xC0);
			sleep(GetSoundLen(rayman1)+1);
		}
SetWallCel(name,s);
	}

What I saw on the messages is random numbers until it hits 0 then music.

/Edward
Edward's Cognative Hazards
2003-03-10, 11:32 AM #6
Hello? Any one home?
Edward's Cognative Hazards
2003-03-11, 5:25 AM #7
HEEEEEEEELLOOOW?
Edward's Cognative Hazards

↑ Up to the top!