Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-26-2003, 10:45 PM
GoZelda GoZelda is offline
Mister 1,000,000
GoZelda's Avatar
Join Date: Jan 2003
Location: Brussels, capital of Europe.
Posts: 5,396
GoZelda will become famous soon enough
Send a message via AIM to GoZelda Send a message via MSN to GoZelda
Explaination of for

Well, it seemed to me that some people are very unfamiliar with for.

This is what for actually is:
NPC Code:

i = 0;
while (i<50){
i++;
)



So, for works like this:

Quote:
First, there's the "statement". This is, i = 0;.
for (i=0; ----){}
then, comes a "test".
i<50;
for (i=0;i<50){}
and then an "operation"
for (i=0;i<50;i++){}
So, i becomes zero. As long as i is less then 50, 1 will be added to i, until it becomes 50 (or more).
Note: never use

NPC Code:

for (i=0;i<1;i--){}


if you don't want an uber-lagged level with an infinite for-loop.

So, once more:

Quote:
I becomes equilevant to zero. As long as i is less then 50, then there's added one to i.
Ofcourse, you can add much more to a loop.

NPC Code:

for (i=17;i>0;i--){}


for example. I hope you see all possibilities of i. Here's a nice example:

NPC Code:

if (timeout||playerenters){
this.savex=0;
for (i=1;i<64;i++){
showpoly 2,{this.savex,32,i,32};
this.savex=i;
sleep 0.05;
}
timeout = 0.05;
}

__________________

Quote:
Originally Posted by Lance
stefan is satan
I am the best.
[URL removed]Music or aural pollution?
Reply With Quote
  #2  
Old 09-26-2003, 11:43 PM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Re: Explaination of for

Quote:
Originally posted by GoZelda

NPC Code:

for (i=0;i<1;i--){}


if you don't want an uber-lagged level with an infinite for-loop.
[/CODE]
Not exactly, serverside it'll give you an error message sent to the NC if the loops excedes 10000 runs after it's done and stop the loop from going further, it wont lag clientside unless you do something to cause it to lag, for(i=0; i<1; i--) wont cause the level to lag on it's own without you doing anything
Reply With Quote
  #3  
Old 09-27-2003, 12:09 PM
GoZelda GoZelda is offline
Mister 1,000,000
GoZelda's Avatar
Join Date: Jan 2003
Location: Brussels, capital of Europe.
Posts: 5,396
GoZelda will become famous soon enough
Send a message via AIM to GoZelda Send a message via MSN to GoZelda
I'm not so familiar with //#CLIENTSIDE and serverside, does anybody know any good tutorial?
__________________

Quote:
Originally Posted by Lance
stefan is satan
I am the best.
[URL removed]Music or aural pollution?
Reply With Quote
  #4  
Old 09-27-2003, 12:13 PM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Your 'nice' example is quite the opposite. If you're attempting to teach people then you should indent, and you shouldn't encourage them to do icky things like putting sleeps in loops.
__________________
Reply With Quote
  #5  
Old 09-28-2003, 07:51 PM
GoZelda GoZelda is offline
Mister 1,000,000
GoZelda's Avatar
Join Date: Jan 2003
Location: Brussels, capital of Europe.
Posts: 5,396
GoZelda will become famous soon enough
Send a message via AIM to GoZelda Send a message via MSN to GoZelda
But Kaimetsu, if i were to create a NPC that would make the level slightly darker every 0.05 seconds, then wouldn't a for loop with sleep be the best solution?
Oh yeah, here's some strange stuff i did with for loops and polygons o.o
Attached Files
File Type: nw lines.nw (12.5 KB, 111 views)
__________________

Quote:
Originally Posted by Lance
stefan is satan
I am the best.
[URL removed]Music or aural pollution?
Reply With Quote
  #6  
Old 09-28-2003, 09:00 PM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
use a timeout instead
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial
Reply With Quote
  #7  
Old 09-28-2003, 10:26 PM
GoZelda GoZelda is offline
Mister 1,000,000
GoZelda's Avatar
Join Date: Jan 2003
Location: Brussels, capital of Europe.
Posts: 5,396
GoZelda will become famous soon enough
Send a message via AIM to GoZelda Send a message via MSN to GoZelda
Yes, but what if i'd wanted to repeat my action? In my "nice" example above, it'd repeat without trouble. How would it work with timeout? You can save some trouble with a sleep for loop. And i don't really see what's wrong with sleep :/
NPC Code:

if (playerenters){
i=1;
this.savex=0;
timeout = 0.05;
}
if (timeout){
if (i<64){
i++;
showpoly 2,{this.savex,32,i,32};
this.savex=i;
} if (i==63){
i=1;
this.savex=0;
}
timeout = 0.05;
}

__________________

Quote:
Originally Posted by Lance
stefan is satan
I am the best.
[URL removed]Music or aural pollution?
Reply With Quote
  #8  
Old 09-28-2003, 11:02 PM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally posted by GoZelda
But Kaimetsu, if i were to create a NPC that would make the level slightly darker every 0.05 seconds, then wouldn't a for loop with sleep be the best solution?
No.

Quote:
Originally posted by GoZelda
Yes, but what if i'd wanted to repeat my action? In my "nice" example above, it'd repeat without trouble. How would it work with timeout? You can save some trouble with a sleep for loop. And i don't really see what's wrong with sleep :/
Too many things to list. If you can't think of an easy way to do it with timeout, you shouldn't call yourself a scripter.
__________________
Reply With Quote
  #9  
Old 09-29-2003, 12:06 AM
protagonist protagonist is offline
Banned
protagonist's Avatar
Join Date: May 2003
Location: CAW
Posts: 5,586
protagonist is on a distinguished road
Send a message via AIM to protagonist Send a message via MSN to protagonist
Quote:
Originally posted by GoZelda
But Kaimetsu, if i were to create a NPC that would make the level slightly darker every 0.05 seconds, then wouldn't a for loop with sleep be the best solution?
Oh yeah, here's some strange stuff i did with for loops and polygons o.o
No way man, it'd be like a flash.
Reply With Quote
  #10  
Old 09-29-2003, 12:10 AM
zs0 zs0 is offline
pothed 5lyf
zs0's Avatar
Join Date: May 2002
Location: o_o
Posts: 1,008
zs0 is on a distinguished road
Stupid advanced scripting :/..
__________________




Quote:
Originally Posted by Scott
GREAT AND I THOUGHT IT WAS BLOODY SPECIAL, THANKS GUYS FOR REMOVING ANY INDIVIDUALITY I MIGHT OF ONCE HAD. GOD THE WORD REVOVLES AROUND YOU DOESN'T IT? SCOTT CAN'T HAVE ONE BIT OF FUN. ZEN THIS. MYKEL THAT. DEEK BLAH BLAH. OMFG. IM GOING TO SLIT MY WRISTS!!!
Reply With Quote
  #11  
Old 09-29-2003, 12:25 AM
protagonist protagonist is offline
Banned
protagonist's Avatar
Join Date: May 2003
Location: CAW
Posts: 5,586
protagonist is on a distinguished road
Send a message via AIM to protagonist Send a message via MSN to protagonist
Quote:
Originally posted by zs0
Stupid advanced scripting :/..
It's not very advanced.
It works like this:

for(a;b;c){ stuff (optional); }


a. The variable, and what you want it to start as (for example a = 0)
b. The condition that has to happen when you want c to happen.
c. The change to a variable that you want to happen (NOTE: Doesn't have to be the same variable as a, but be careful not to infinite for loop. In other words, where the optional place is you have to make it catch the variable at some point and stop the for loop. Otherwise you will crash your graal).
Reply With Quote
  #12  
Old 09-29-2003, 02:38 PM
GoZelda GoZelda is offline
Mister 1,000,000
GoZelda's Avatar
Join Date: Jan 2003
Location: Brussels, capital of Europe.
Posts: 5,396
GoZelda will become famous soon enough
Send a message via AIM to GoZelda Send a message via MSN to GoZelda
Quote:
Originally posted by Kaimetsu


No.



Too many things to list. If you can't think of an easy way to do it with timeout, you shouldn't call yourself a scripter.
Okay, the level-darkening stuff isn't hard with timeout.
But, Kai, can you please explain me what is wrong with sleep?
__________________

Quote:
Originally Posted by Lance
stefan is satan
I am the best.
[URL removed]Music or aural pollution?
Reply With Quote
  #13  
Old 09-29-2003, 03:52 PM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally posted by GoZelda

Okay, the level-darkening stuff isn't hard with timeout.
But, Kai, can you please explain me what is wrong with sleep?
Just trust me on this one, dude.

I'll probably add a mention to KSI-GS at some point, you can read it then.
__________________
Reply With Quote
  #14  
Old 09-29-2003, 04:09 PM
GoZelda GoZelda is offline
Mister 1,000,000
GoZelda's Avatar
Join Date: Jan 2003
Location: Brussels, capital of Europe.
Posts: 5,396
GoZelda will become famous soon enough
Send a message via AIM to GoZelda Send a message via MSN to GoZelda
Quote:
Originally posted by Kaimetsu


Just trust me on this one, dude.
I don't doubt you're right, really.
If you were wrong, you would've been jumped and raped totally by now -.-
__________________

Quote:
Originally Posted by Lance
stefan is satan
I am the best.
[URL removed]Music or aural pollution?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:51 AM.


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