3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: Execute script by each detection scanner.  (Read 158 times)

« on: June 19, 2014, 07:33:59 PM »
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
« Reply #1 on: June 19, 2014, 07:42:31 PM »
Here is the image
« Reply #2 on: June 20, 2014, 08:39:27 AM »
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
« Last Edit: June 20, 2014, 09:17:06 AM by Mike Hense »
« Reply #3 on: June 21, 2014, 04:18:24 PM »
Hello, I'll try - TheHades24
« Reply #4 on: June 24, 2014, 07:50:25 AM »
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.
« Reply #5 on: June 25, 2014, 05:31:21 AM »
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...

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  :D )...

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
« Last Edit: June 25, 2014, 05:49:05 AM by Mike Hense »
« Reply #6 on: June 25, 2014, 09:21:30 AM »
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
« Reply #7 on: June 26, 2014, 05:49:36 AM »
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...

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

« Last Edit: June 26, 2014, 06:35:40 AM by Mike Hense »
« Reply #8 on: June 26, 2014, 06:36:48 AM »
ok... you posted before i finished...

good that it now works...

--Mike
« Reply #9 on: June 26, 2014, 10:47:06 AM »
Hi Mike, thanks for the explanation, I'll work it when I get home, I will answer you soon, greetings - TheHades24

 ;D
Pages: [1]