Thread: % and timevar
View Single Post
  #9  
Old 02-21-2003, 04:16 AM
PrinceDark PrinceDark is offline
Criminal X
PrinceDark's Avatar
Join Date: Feb 2003
Location: Miami, Florida
Posts: 662
PrinceDark will become famous soon enough
%
A simple example
NPC Code:

dir=(dir+2)%4;



So let's say you have a npc that has onwall checks and you want it to turn in the other direction when it is at a certain distance from the wall. The above code will make it turn in the opposite direction.

if dir==1. So if the npc has onwall detection while heading left, and it gets near the wall and performs this command it will change the direction to 3.

So to break it down.
dir=(dir+2)%4;
=(1+2)%4
=3 - int(3 / 4) * 4
=3 - int(.75) * 4
=3 - 0*4
=3 - 0

So in the end it will be dir=3

There's another way to rotate the player or npc's. I think it's dir=(dir+1)%4; and it rotates clockwise or counterclockwise. Something like that.

--
For timevar I have no clue. I never used it before and I'll be learning it now when people explain it in this thread I suppose.
__________________
- Criminal X: certified nut case
Reply With Quote