Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   This. again (https://forums.graalonline.com/forums/showthread.php?t=15980)

iceman8832 11-02-2001 07:37 AM

This. again
 
i'm just wondering if someone could give me an example script telling me what everything does. I would like the script to have this. in it a lot. i htink i understand better but not completely. could you tell how to set it and what is the point.:confused:

Python523 11-02-2001 07:47 AM

Well, This. is a type of variable, there are two different kinds of variables, global (every npc in the room) and this (which is only of the specific npc)

wark2 11-02-2001 10:28 PM

yeah, i think pythons right....

PresShinP2P 11-02-2001 11:24 PM

are regular vars are shared with other people in the same room?

Xaviar 11-03-2001 02:28 AM

Quote:

Originally posted by PresShinP2P
are regular vars are shared with other people in the same room?
A global variable (ie: thisismyvariable = 10) is readable by any NPC in the level it was declared in. A local variable (ie: this.thisismyvariable = 10) is readable only by the npc that created it.

LiquidIce00 11-03-2001 03:10 AM

if you have 2 npc's one is like

if (playerenters) { on=1; }

then the other

if (playerenters) { on=2; }

they would confuse each other, because they would be sharing it, but if you have

if (playerenters) { this.on=1; }

then the other

if (playerenters) { this.on=2; }

then on for the 1st script would be 1 and on for the 2nd script would be 2 .. they would be variables for the npc itself

Loriel 11-03-2001 03:33 AM

Basically you can say:
If you want a variable to stay the same for some time, use this.stuff, if that's not needed or you want to use it also on other NPCs, you use normal variables.
For example, hiding 10 showimgs ...
NPC Code:
for (i=0; i<10; i++)
hideimg i;


... can be done with normal variables (less typing work :) and looks nicer), but a movement using for-loops...
NPC Code:
for (this.i=0; this.i<10; this.i++)
if (insert complicate onwall check) {
x += vecx(dir)*0.5;
y += vecy(dir)*0.5;
sleep 0.05;
}


... would need to be done with this.vars, because some other NPC would probably use the same variable for his stuff and confuse the moving one.
A switch for example...
NPC Code:
 Switch:
if (washit) {
switchhit = true;
setimg insert switch image;
sleep 5;
switchhit = false;
setimg insert other switch image;
}

Door:
if (playertouchsme && switchhit==true) {
hide;
sleep 3;
show;
}


... would need to be done with normal variables because the other NPC is checking it.


And always, all variables (besides NPC or playerstats (All stuff you can check with npcs/players[index].blah)) are always local and not sent to other people (unless it's a serverside NPC of course).

Bash me if I am wrong, but I think I am not.

btedji 11-03-2001 04:19 AM

go look at the other posts, there was a really good explanation not too long ago

Loriel 11-03-2001 04:41 AM

Quote:

Originally posted by btedji
go look at the other posts, there was a really good explanation not too long ago
You don't like my one? DIE DIE DIE ;)

iceman8832 11-03-2001 07:02 AM

i still don't really understand. could you give me an example script that someone uses. and tell me why you use this. and what it is for. could you explain it in very good detail every part and what they do. for ex. this.rupee=10 would that work? and if so what would rupee be for. and why 10. what would the = do.:(

SSRobgeta 11-03-2001 08:09 AM

A Quote:
One who dies... Well... Dies

TDO2000 11-03-2001 09:23 AM

So the third use of my description:
variables:
there are 2 types of variables
1. the global (for every NPC in the room)
2. this. variables for only one NPC

variables are used for numbers and stuff like this...
example

if(playertouchsme){
a=1+3;
message #v(a);
}

if u touch him he will say 4 =)

so this variables:

if u have an NPC which uses normal variables (without this) it is set for all npcs in the level
example:
1. NPC:
if(playertouchsme){
a=1+3;
message #v(a);
}

2. NPC
if(playertouchsother){
message #v(a);
}

so if u touch the 1. NPC both will say 4

if u use this.variables
example:
1. NPC:
if(playertouchsme){
this.a=1+3;
message #v(a);
}

2. NPC
if(playertouchsother){
message #v(this.a);
}

then if u touch the first NPC it will say 4 but the second will say 0 (it's what every variable is before u set it)

hope u'll understand and Loriel it's always good to use things no new scripter will understand to explain how something like this.-variables work...


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

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