Hi all, I have the following question, I know how to detect rigid body with a scanner, and I want to use script as a down counter so that every time it is detected, one can reduce the variable as in the example, but the problem is that, just once detected, the script runs infinitely and infinitely variable reduces to negative, the question is how to make the script run once for each time it is run the detection, Greetings - TheHades24
This forum is now archived!
- Welcome to the archive!
News:
The 3DRad community can be found at classdev.net.
- 3D Rad - Free 3D game maker - Forum >
- General Category >
- 3D Rad - Technical Discussion >
- Execute script by each detection scanner.
Author Topic: Execute script by each detection scanner. (Read 158 times)
simply add a switch to the logic...
a variable that will flip from open to close on a collision event, and maintain that value until there is no longer any collisions detected...
allow the decrement to occur only on collision and when the switch is open...
--Mike
a variable that will flip from open to close on a collision event, and maintain that value until there is no longer any collisions detected...
allow the decrement to occur only on collision and when the switch is open...
--Mike
Hi Mike, I try this but not work, even if I write the variable Y in the Main, only decreases once, being in 19 and will not run again , you can put a example code, greetings.
two things...
1 - indentations in code are done to organize the code into easily recognizable chunks... that is all, nothing else... you've got it a lil messed up... not too bad, but it seems as if you're just indenting for the sake of indenting... you indent after each conditional, if there is a block of conditional logic to follow... just to keep things organized...
like so...
do you see how each if is followed by a block of indented code... not a really big deal... until you're trying to debug some code or change some logic (which happens more often than not)...
2 - i don't see any comments in your code... you'll never make anything if you don't first write out the logic as comments... just simply write out the logic (in plain english), check it to see if it makes sense... after you do this, and if the logic makes sense... simply write the code around the logic comments...
remember... it's the logic that determines if your code will work (syntax errors not taken into account )...
write the logic (comments only, no code) out and we'll have it fixed in a second... make the comments short, sweet, and to the point...
--Mike
1 - indentations in code are done to organize the code into easily recognizable chunks... that is all, nothing else... you've got it a lil messed up... not too bad, but it seems as if you're just indenting for the sake of indenting... you indent after each conditional, if there is a block of conditional logic to follow... just to keep things organized...
like so...
Code: [Select]
float x = 20;
float y = 1;
void Main(){
if(y > 0) {
x = x - 1;
OUT_22 = x;
}
}
do you see how each if is followed by a block of indented code... not a really big deal... until you're trying to debug some code or change some logic (which happens more often than not)...
2 - i don't see any comments in your code... you'll never make anything if you don't first write out the logic as comments... just simply write out the logic (in plain english), check it to see if it makes sense... after you do this, and if the logic makes sense... simply write the code around the logic comments...
remember... it's the logic that determines if your code will work (syntax errors not taken into account )...
write the logic (comments only, no code) out and we'll have it fixed in a second... make the comments short, sweet, and to the point...
--Mike
Hello Mike, corrected and hopefully power understand...
The problem is that single once reduced, remaining at 19 and does not reduce to the following detections, help me, greetings
The problem is that single once reduced, remaining at 19 and does not reduce to the following detections, help me, greetings
ok... now, just looking at your comments, i can see what it is that you're trying to do...
first, a misconception i see... the script doesn't stop running because a variable changes... the script is always running, executing itself about 60 times a second... in order to stop a script you either need to call iScriptStop() or have another script call iObjectStop()... both of which (i think) should be avoided, except in only the most extreme circumstances...
don't treat a script object as you would other objects... if you have a script in your project, then either let it run, or else remove it... stopping a script means your logic is faulty, and hasn't been thought out clearly... it's not the script you wanna control, it's the action in response to an event or variable change... you don't stop a script just because an event hasn't occurred...
also...
a single script isn't restricted to doing only one thing... on the contrary, a script in its most optimized form, is capable of doing many things... another reason you don't want to be stopping and restarting a script as a matter of habit...
ok... with that in mind, lets look at your logic again...
we can now correct it to read...
ok... that looks good, doesn't it... well, yeah... if you don't think things through...
are we gonna let the scanner hit and hit it forever, decreasing the health forever... the health will eventually reach zero and go way below it... i'm sure that's not what you want...
so we revisit the logic and make a small change...
now this logic looks complete (we can add health power ups, but that's for another post)...
so now, lets use the logic and see how you code applies, or not...
first the variable declaration... only change i'd make there is to change the names of the variables to something less cryptic... easier to recognize... and y is never used, so get rid of it...
now... implement the logic...
the iMouseClick() function should take care of the "switching" and prevent multiple uncontrolled scanner hits...
lemme know if this helps any...
--Mike
first, a misconception i see... the script doesn't stop running because a variable changes... the script is always running, executing itself about 60 times a second... in order to stop a script you either need to call iScriptStop() or have another script call iObjectStop()... both of which (i think) should be avoided, except in only the most extreme circumstances...
don't treat a script object as you would other objects... if you have a script in your project, then either let it run, or else remove it... stopping a script means your logic is faulty, and hasn't been thought out clearly... it's not the script you wanna control, it's the action in response to an event or variable change... you don't stop a script just because an event hasn't occurred...
also...
a single script isn't restricted to doing only one thing... on the contrary, a script in its most optimized form, is capable of doing many things... another reason you don't want to be stopping and restarting a script as a matter of habit...
ok... with that in mind, lets look at your logic again...
Quote
//This is the script that runs
every time is performed a contact
between the scanner and the rigid body
(which will be the enemy)//
//The objective the script is to reduce
a variable by one each time the script is
executed, the variable will be the life of
the enemy//
we can now correct it to read...
Quote
// reduce the life of the object on each new scanner hit
ok... that looks good, doesn't it... well, yeah... if you don't think things through...
are we gonna let the scanner hit and hit it forever, decreasing the health forever... the health will eventually reach zero and go way below it... i'm sure that's not what you want...
so we revisit the logic and make a small change...
Quote
// if life is greater than zero reduce the life of the object on each new scanner hit
// else object is dead
now this logic looks complete (we can add health power ups, but that's for another post)...
so now, lets use the logic and see how you code applies, or not...
first the variable declaration... only change i'd make there is to change the names of the variables to something less cryptic... easier to recognize... and y is never used, so get rid of it...
Code: [Select]
float life = 20;
now... implement the logic...
Code: [Select]
float life = 20;
void Main(){
if(iMouseButtonClick(0))iObjectStart(OBJ_22); // shoot the scanner
if( life > 0 ){ // if life is greater than zero
if(IN_22 > 0){ // and object is hit by scanner
life--; // decrease health
}
}
OUT_44=life; // debug: show the life status in a value print
}
}
the iMouseClick() function should take care of the "switching" and prevent multiple uncontrolled scanner hits...
lemme know if this helps any...
--Mike
Pages: [1]