Here is my code:
	
	
	
		
In the process enemy(), there is a random number generator that picks a number between 1 and 50. If that number ends up at 45, the enemy is supposed to fire. What happens here is, the enemy continuously fires. enfireflag always gets set, but seedfire always ends up at 45, regardless of what number I put in the rand() function. For example, I put 1,30 in rand() and the enemy STILL fires. seedfire STILL ends up as 45!
I've been staring at this for a few hours now and have tried a number of attempted fixes with no luck. Is there something wrong with the code that I cannot see?
Any help would be greatly appreciated.
				
			
		Code:
	
	PROGRAM ship_shoot;
GLOBAL
sprites;
shotflag;
score=0;
lives=3;
seedfire=0;
enfireflag=0;
PRIVATE
Begin
graph_mode=mode_16bits;
set_mode(m640x480);
sprites=load_fpg("new.fpg");
write_int(0,10,25,0,offset score);
write_int(0,10,35,0,offset enfireflag);
write_int(0,10,45,0,offset seedfire);
ship(320,420);
enemy();
end
process ship(x,y);
private
begin
graph=1;
	loop
  if (key(_left) and x>=30)
  	x-=20;
  end
  if (key(_right) and x<=610)
  	x+=20;
  end
  if (key(_esc))
  	exit();
  end
  if (key(_control)and NOT shotflag)
  	shot(x,y);
  end
	frame;
	end
end
process shot(x,y);
private
collflag;
begin
graph=5;
shotflag=1;
Loop
y-=40;
collflag=collision(type enemy);
  if(y<-10)
  	shotflag=0;
  return;
  end
  if (collflag)
  	signal(collflag,s_kill);
  	shotflag=0;
  	score+=100;
  signal(type shot,s_kill);
  end
	frame;
	end
end
process enemy();
private
begin
graph=2;
x=10;
y=100;
loop
x=x+15;
  if (x>640)
  	x=10;
  end
  if (seedfire=45 and NOT enfireflag)
  	enfireflag=1;
  	enemyfire(x,y);
  	seedfire=rand(1,50);
  end
	frame;
	end
end
process enemyfire(x,y);
begin
graph=5;
loop
y=y+20;
  if (y>420)
  	signal(type enemyfire,s_kill);
  	enfireflag=0;
  	return;
  end
  if (collision (type ship))
  	signal(type ship, s_kill);
  	return;
  end
	frame;
	end
end
	In the process enemy(), there is a random number generator that picks a number between 1 and 50. If that number ends up at 45, the enemy is supposed to fire. What happens here is, the enemy continuously fires. enfireflag always gets set, but seedfire always ends up at 45, regardless of what number I put in the rand() function. For example, I put 1,30 in rand() and the enemy STILL fires. seedfire STILL ends up as 45!
I've been staring at this for a few hours now and have tried a number of attempted fixes with no luck. Is there something wrong with the code that I cannot see?
Any help would be greatly appreciated.
	