Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Ok now why wont this work? (https://forums.graalonline.com/forums/showthread.php?t=9392)

Bhala 08-12-2001 08:14 AM

Ok now why wont this work?
 
Why wont this work?

NPC Code:
if (playerenters) {
drawunderplayer;
dontblock;
timereverywhere;
timeout = .5;
}
if (timeout){
this.dir = random( 1, 5 );
if (this.dir=1 && !onwall(x+1,y)){y-=1;}
if (this.dir=2 && !onwall(x+.5,y+2)){y+=1;}
if (this.dir=3 && !onwall(x,y)){y-=1;}
if (this.dir=4 && !onwall(x,y)){y-=1;}
timeout = .5;
}


Xaviar 08-12-2001 08:20 AM

Re: Ok now why wont this work?
 
Quote:

Originally posted by Bhala


this.dir = random( 1, 5 );


should be

this.dir = int(random(1,5));

LiquidIce00 08-12-2001 08:23 AM

ur onwall is messy tho

Bhala 08-12-2001 08:28 AM

yea I know about the onwall stuff but I know why that wasnt making it work


thx

Falcor 08-12-2001 03:24 PM

dir = (dir+int(random(1,4)))%4;

Thats nice a neat =D

Jerom 08-13-2001 08:35 AM

Re: Ok now why wont this work?
 
Quote:

Originally posted by Bhala
Why wont this work?

NPC Code:
if (playerenters) {
drawunderplayer;
dontblock;
timereverywhere;
timeout = .5;
}
if (timeout){
this.dir = random( 1, 5 );
if (this.dir=1 && !onwall(x+1,y)){y-=1;}
if (this.dir=2 && !onwall(x+.5,y+2)){y+=1;}
if (this.dir=3 && !onwall(x,y)){y-=1;}
if (this.dir=4 && !onwall(x,y)){y-=1;}
timeout = .5;
}


When you do random things, doesn't it also do decimals and not just whole numbers?

kyle0654 08-13-2001 09:32 AM

Re: Re: Ok now why wont this work?
 
Quote:

Originally posted by Jerom

When you do random things, doesn't it also do decimals and not just whole numbers?

yep.

Also, the parts where you check stuff like this.dir=3 should be this.dir==3. Quick guide to where to use == as opposed to =:

if = is found inside:
if ()
while ()
or the second part of for ()
then use ==

otherwise, use =

ownerofbabylon 08-13-2001 07:04 PM

Quote:

Originally posted by Kaimetsu


And inefficient...

LOL great to have you back Kai

Jerom 08-14-2001 03:32 AM

Re: Re: Re: Ok now why wont this work?
 
Quote:

Originally posted by kyle0654

yep.

Also, the parts where you check stuff like this.dir=3 should be this.dir==3. Quick guide to where to use == as opposed to =:

if = is found inside:
if ()
while ()
or the second part of for ()
then use ==

otherwise, use =

But I remember trying to make a baddie, and it would change directions according to what ranges of a number a certain variable was in. I had used the same method before, but it didn't work in my baddie for some reason. I guess I'll have to look over it again.


All times are GMT +2. The time now is 07:26 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.