It does what it likes -.-

Posted By: hopfel

It does what it likes -.- - 01/23/10 21:00

Hi, me again.
I'm programming on a little rpg and I made this little very easy code to check, if the player went out 5 fire:

while(firenumber<5){wait(1);} //wait as long as the player went out all fires

And in the function from the fire:

if( -water on me-)
firenumber+=1;

But now, if I went out all fires ingame, nothing happens. I made a digit for the variable firenumber, and it's on 5 and anyway nothing happens. I worked with beep(); so i'm sure the fault is in the Code, which I wrote here.
Posted By: Oxy

Re: It does what it likes -.- - 01/23/10 21:53

try to first set firenumber to 5 at start, to see if
the stuff after the while works.
If this works, test if the "water an" condition is triggered correctly.
Posted By: hopfel

Re: It does what it likes -.- - 01/23/10 22:04

I tried this:

beep();
while(firenumber<5){wait(1);}
beep();

The first beep comed, but not the second smirk
And how I said, I made a digit on a panel for the variable "firenumber", and it counts fine...

EDIT:
I tried this:

beep();
while(firenumber<5){beep();wait(-1);} //beep every second
beep();beep();beep();beep(); //make four fast beeps

Ingame, it beeped first, then it beeped every second.
But when I extinguished one fire, it stopped beeping, but not four fast beeps. The whole function got stuck (maybe) It's so confusing :S
Posted By: Ottawa

Re: It does what it likes -.- - 01/24/10 14:39

Hi!

try

Code:
beep();
while(firenumber<5)
{
    for (var i=1; i<5; i++)
         {
           beep();wait(-1);
         } //beep every second
 }



not tested

Posted By: hopfel

Re: It does what it likes -.- - 01/24/10 14:55

no, it did the same... first beep comed and then it beeped every second, if I extinguished one of the five fires, it stopped beeping.
Posted By: Ottawa

Re: It does what it likes -.- - 01/24/10 15:08

Hi hopfel!
Quote:

if I extinguished one of the five fires, it stopped beeping


Verify your panel to make sure that it shows the numbers going from
1 to 5.

Make the wait longer to slow things down.
Posted By: hopfel

Re: It does what it likes -.- - 01/24/10 15:35

I wrote this code:
beep();
var i = 0;
while(firenumber<5)
{
for (i=1; i<5; i++)
{
test = i;
beep();wait(-2);
} //beep every second
}

This was the operational sequence:

- firenumber = 0
*beep*
*beep*
(1 second later)
*beep*
- i = 1
(1 second later)
*beep*
- i = 2
(1 second later)
*beep*
- i = 3
(1 second later)
*beep*
- i = 4
(1 second later)
*beep*
- i = 1
- I extinguished one of the five fires
- firenumber = 1
(1 second later)
-nothing happened, i stayed on 1.
- I extinguished the other four fires
- firenumber = 5
- nothing happened


I think it's the same strange problem from here:

http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Main=36996&Number=302333#Post302333
Posted By: Ottawa

Re: It does what it likes -.- - 01/24/10 16:13

Hi!

Once the value of firenumber is 5 it stays 5 until you reset it in your code.
Do you reset it for the next fire?
Posted By: hopfel

Re: It does what it likes -.- - 01/24/10 18:57

On the digit the firenumber is zero, before I extinguish a fire, if I understanded your question right.
Posted By: Ottawa

Re: It does what it likes -.- - 01/25/10 00:04

Hi!

A few questions

How many players are putting the fire out?

Is this the situation?
Quote:

You have 5 fires
You have to put water on them

firenumber is 0 when your start
code to repeat this action until firenumber is 5
the fire is on
put water on this fire
firenumber is +1
fire is out
repeat


You will have to give us some code to work with.
Posted By: FoxHound

Re: It does what it likes -.- - 01/25/10 04:05

Rename your var and see what happens. Honestly I have had this help before. Usually from spelling mistakes you can't see. If not then could you post a bit more of your code so we can see more of what is happening.
Posted By: hopfel

Re: It does what it likes -.- - 01/25/10 19:46

Ok, here some more code; The game is german, so the variables are German too, I tried to commend them that you can understand it. This is the whole fire-function:

function feuer(pox,poy)
{
var aufgenommen=0; //create the variable "aufgenommen"
if(feuani==-2)
{animationfeuer();
feuani=0;} //animate the fire
PANEL* feua = pan_create("pos_x=0;pos_y=0;flags=OVERLAY | VISIBLE;",8); //create the fire
pan_setwindow(feua,0,0,0,30,18,feu_bmp,feuani,0); //animate the fire with window
my = ent_create("gegum.mdl",nullvector,NULL); //give the fire an entity
my.skill3=50; //live of the fire
my.flags=INVISIBLE; //set the Entity on invisible
my.skill6=2;
while(my.skill3>=0) //repead while the life of the fire is bigger than zero
{
vec_set(my.x,vector(feua.pos_x+15*my.skill3/50,feua.pos_y+9*my.skill3/50,0)); //set the position of the entity on the position of the fire-panel
feua.pos_x=stage_a.pos_x+pox-15*my.skill3/50;
feua.pos_y=stage_a.pos_y+poy-9*my.skill3/50; //position of the fire on the map named "stage_a"
feua.scale_x=my.skill3/50;
feua.scale_y=my.skill3/50; //scale the fire proportional with his live
if(my.skill3<50)
my.skill3+=1*time_ste; //rebuild the fire from time to time
wait(1);
}
media_tune(snd_play(zisch_snd,NULL,100),100,150,100); //make a sound
ptr_remove(feua); //delete the fire-panel
ent_remove(my); //delete the entity from the fire
feuerzahl+=1; //count the firenumber
}


And there the whole code for the water:


function distanz(pox, poy) //This function is triggered by the player
{
attart = bmap_create("att1.bmp"); //create the bitmap
PANEL* flobj = pan_create("pos_x=0;pos_y=0;bmap=attart;flags=OVERLAY | VISIBLE;",10); //create the water-panel
var posl[2];
posl[0]=pox;
posl[1]=poy; //set the positions
while(flobj.skill_x<100&&flobj.skill_y==0) //repeat until it finds a target or the time is off
{
flobj.pos_x=stage_a.pos_x+posl[0]-4.5;
flobj.pos_y=stage_a.pos_y+posl[1]-4.5; //set the positions on the map
flobj.skill_x+=4*time_step; //count the skill_x of the panel
posl[1]-=16*time_step; //move the water
if(vec_dist(vector(pox,poy,0),vector(posl[0],posl[1],0))>18) //if the water is away from this one who shots
{c_scan(vector(flobj.pos_x+4.5,flobj.pos_y+4.5,0),my.pan,vector(360,0,9),NULL);} //look for targets
if(you) //if there's a target
{
if(vec_dist(you.x,vector(stage_a.pos_x+posl[0]-4.5,stage_a.pos_y+posl[1]-4.5,0))<=9) //if the target near you
{
effectiv = 30;
you.skill3-=effectiv; //damage the target

if(flobj.skill_y==0)
{
snd_play(platsch_snd,NULL,effectiv*3); //make a sound
flobj.skill_y=1;}
}}
wait(1);
}
pan_remove(flobj); //remove the water
}


And last, the function of the scenario (cutted):

function part_3()
{

.
.
.

feuer(200,850);
feuer(130,920);
feuer(240,1000);
feuer(400,980);
feuer(270,920); //create the fires

.
.
.

dialog("Lösche alle Feuer!"); //function for a dialog
.
.
.

beep();
var i = 0;
while(feuerzahl<5) //the test-loop from ottawa
{
for (i=1; i<5; i++)
{
test = i; //test is a value, who I see on a digit
beep();wait(-2);
} //beep every second
}
beep();beep();beep();beep(); //test, if the function continues

.
.
.

}

The whole code works, only this problem with the firenumber don't do what it should do. Hope, there are enough informations.
Posted By: Lion_Ts

Re: It does what it likes -.- - 01/25/10 22:21

The sample at the thread start is correct. just try it and you should see.
I have free 5min and just tried your sample:
Code:
INT32 firenumber = 0;

function inc_firenumber()
{
	++firenumber;
	DBG_INFO1("firenumber:%d.", firenumber)
}

function clear_firenumber()
{
	firenumber = 0;
	DBG_INFO1("firenumber:%d.", firenumber)
}

void main()
{
	on_i = inc_firenumber;
	on_c = clear_firenumber;
	while(firenumber<5)
	{
		DBG_INFO1("inside loop - firenumber:%d.", firenumber)
		wait(-1);
	} 
	DBG_INFO1("EXIT firenumber:%d.", firenumber)
}



this is the console output (I pressed the 'I' key periodically):
Code:
[INF|temp_test.c|main] inside loop - firenumber:0.
[INF|temp_test.c|inc_firenumber] firenumber:1.
[INF|temp_test.c|main] inside loop - firenumber:1.
[INF|temp_test.c|main] inside loop - firenumber:1.
[INF|temp_test.c|inc_firenumber] firenumber:2.
[INF|temp_test.c|main] inside loop - firenumber:2.
[INF|temp_test.c|main] inside loop - firenumber:2.
[INF|temp_test.c|main] inside loop - firenumber:2.
[INF|temp_test.c|inc_firenumber] firenumber:3.
[INF|temp_test.c|main] inside loop - firenumber:3.
[INF|temp_test.c|inc_firenumber] firenumber:4.
[INF|temp_test.c|main] inside loop - firenumber:4.
[INF|temp_test.c|main] inside loop - firenumber:4.
[INF|temp_test.c|inc_firenumber] firenumber:5.
[INF|temp_test.c|main] EXIT firenumber:5.


there are few reason to get failed with your loop:
- a global variable modified suddenly (somewhere in your code); for example, inside an action of many concurrent entities;
- global variable has wrong type (comparing with 'while' statement); for example using signed or high precision var to test smth like: "x == .5"
- wrong 'while' statement;

suggestions:
- at first, search over your files for the 'firenumber' to see, where you try to modify it.
- at second, add more debug printouts to see the execution flow.
- try to debug.
Posted By: hopfel

Re: It does what it likes -.- - 01/26/10 12:34

Jea grin Thank you to take your time to try to lift this problem. wink
But I discovered, the variable 'firenumber' is not the fault;
I displaced "while(firenumber<5){wait(1);}" with "while(!key_space)wait(1);"
If I press space before I extinguishe one fire, it works fine. If I extinguishe one fire before I press space, nothing happens. So the fire-function must make the scenario-function stuck. So I wrote this five lines:

feuer(200,850);
feuer(130,920);
feuer(240,1000);
feuer(400,980);
feuer(270,920);

In another function and, I was amazed, it works!
To test something I replaced the "my" from the fire-function with another entity-pointer and it works with this five lines in the scenario-function also. So I ask me; why gets a function stuck, if I remove his "my" pointer?
© 2023 lite-C Forums