Graal Forums

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

WHIPENIE4 02-27-2002 04:07 AM

Variables
 
Ok im slowly learning how to script , im kinda stuck on varibles... when do you use them??

In the example they use in npcprogramming
myvar = 1;
if (myvar==1) {..........}

So if the varible ='s 1 then the command in {.....} will be executed...... but lets say
the command in the {...} was messageHello;
then why not just put
If (playertouchsme) messageHello;
???
Or 'playerenters'

[edit]Also what do these symbols mean
>,<,>=,<=,==,!= , or when do you use them?[/edit]

nyghtGT 02-27-2002 04:23 AM

Re: Variables
 
Quote:

Originally posted by WHIPENIE4
Ok im slowly learning how to script , im kinda stuck on varibles... when do you use them??

In the example they use in npcprogramming
myvar = 1;
if (myvar==1) {..........}

So if the varible ='s 1 then the command in {.....} will be executed...... but lets say
the command in the {...} was messageHello;
then why not just put
If (playertouchsme) messageHello;
???
Or 'playerenters'

[edit]Also what do these symbols mean
>,<,>=,<=,==,!= , or when do you use them?[/edit]

Well 'if (playertouchsme)' is so if the player touchs the NPC and 'if (myvar==1)' can be set in a variety of ways ...

> - greater than
< - less than
>= - greater than or equal to
<= - less than or equal to
== - is equal to
!= - not equal to (I dont think exists)

TDK_RC6 02-27-2002 04:25 AM

well lets see

you can use variables with flags for certain things, here is a example:

NPC Code:

if (playertouchsme) {
myvar=playerrupees;
if (myvar==0) {
message You have no gralats;
}
if (myvar==1) {
message You have 1 gralat;
}
if (myvar>=2) {
message You have #v(myvar) gralats;
}
sleep 3.4;
message ;
}



>= - great than or equal to
> - greater than
<= - less than or equal to
< - less than
== - equal to
!= - not equal to

if you want to check if a variable is greater than, less than, minimum about (greater than or equal to), maximum number (lesser than or equal to), equal to, or any other number

TDK_RC6 02-27-2002 04:26 AM

Re: Re: Variables
 
Quote:

Originally posted by nyghtGT


!= - not equal to (I dont think exists)

it does exist :P

nyghtGT 02-27-2002 04:30 AM

Quote:

Originally posted by TDK_RC6

NPC Code:

if (playertouchsme) {
myvar=playerrupees;
if (myvar==0) {
message You have no gralats;
}
if (myvar==1) {
message You have 1 gralat;
}
if (myvar>=2) {
message You have #v(myvar) gralats;
}
sleep 3.4;
message ;
}



:D
NPC Code:

NPC Code:

if (playertouchsme) {
for (i=0;i<playerrupees;i++) {
message I gots #v(i) cash monies!
}
}




:D
I know you can do that, I just wanna confooze him ...

TDK_RC6 02-27-2002 04:33 AM

that not nice

nyghtGT 02-27-2002 04:34 AM

Re: Re: Re: Variables
 
Quote:

Originally posted by TDK_RC6


it does exist :P

ok, I just wasn't sure and did not want to give him false info ...

nyghtGT 02-27-2002 04:36 AM

Quote:

Originally posted by TDK_RC6
that not nice
its carrying on the tradition ...

nyghtGT 02-27-2002 04:37 AM

Re: Variables
 
Quote:

Originally posted by WHIPENIE4
Ok im slowly learning how to script , im kinda stuck on varibles... when do you use them??

Would you like a lesson in arrays ?

WHIPENIE4 02-27-2002 04:45 AM

Quote:

Would you like a lesson in arrays ?
Yes pwease:(

nyghtGT 02-27-2002 04:54 AM

Quote:

Originally posted by WHIPENIE4

Yes pwease:(

Variable arrays are an easy way to store multiple values to one variable:

this.variable={0,1,2,3,4,5}

The above sets the arrays for the variable 'this.variable'. To access the arrays you use:

if (this.variable[1]=value) {}

Roughly, that says, if the array 1 of this.variable is equal to a value the contents of {} occur.
Arrays start at 0. So the arrays for that variable would be:

this.variable[0]=0
this.variable[1]=1
this.variable[2]=2
And so on...

WHIPENIE4 02-27-2002 05:34 AM

:eek:

That helped a bit , thanks.
Still a little confuseing though :(

WHIPENIE4 02-27-2002 05:48 AM

Quote:

if (playertouchsme) {
myvar=playerrupees;
if (myvar==0) {
message You have no gralats;
}
if (myvar==1) {
message You have 1 gralat;
}
if (myvar>=2) {
message You have #v(myvar) gralats;
}
sleep 3.4;
message ;
}
Ok let me see , This script would mean

If the player touches the npc and the varible is equal the the amount of ruppees , if the varible is equal to 0 then say You have no gralats , if the varible is equal to 1 then the message is You have 1 gralat, if the varible is greater then 2 message is You have (then i dont know what #v is) the amount the varible is gralets. then sleep for 3.4 secs and the message is nothing...

Am i right?

[edit] Could someone also give me more examples of things with myvar stuff in them?? I want to get this section in scripting down before i go to this.var stuff... [/edit]

nyghtGT 02-27-2002 08:03 AM

Quote:

Originally posted by WHIPENIE4


Ok let me see , This script would mean

If the player touches the npc and the varible is equal the the amount of ruppees , if the varible is equal to 0 then say You have no gralats , if the varible is equal to 1 then the message is You have 1 gralat, if the varible is greater then 2 message is You have (then i dont know what #v is) the amount the varible is gralets. then sleep for 3.4 secs and the message is nothing...

Am i right?

[edit] Could someone also give me more examples of things with myvar stuff in them?? I want to get this section in scripting down before i go to this.var stuff... [/edit]

no, if the player touchs the npc the variable, 'myvar', gets set to the amount of rupees the player has. Then if myvar is equal to 0,1, or 2. It will say, "I have # rupees"

TDK_RC6 02-27-2002 08:39 AM

baby acid, you are right

the #v this is a variable,
if you didnt include that, then it would just show, You have myvar gralats

but when you put, #v(myvar), it reads myvar and outputs the amount of it

slick_soul 02-27-2002 11:18 AM

Okay. I am just completely lost. What is it that whipenie is trying to do and can you re-explain that whole bit about variables and stuff.

nyghtGT 02-27-2002 01:43 PM

Quote:

Originally posted by slick_soul
Okay. I am just completely lost. What is it that whipenie is trying to do and can you re-explain that whole bit about variables and stuff.
he is just wondering how variables how used and set ...

if anyone needs firther help i made this ...

http://nyght.digitalrice.com/variables.php

Saga2001 02-27-2002 10:12 PM

good definition of arrays, read it, and i am sure u'll undertstand.
NPC Code:

// to make an array do this:
// setarray arrayname,size;
// as in this example:
setarray this.values,10;
/*
to set values in an array do this:
arrayname[indexnumber] = value;
the first index in every array is 0.
so if you have an array that you set to size 100
than its 0-99.
as in this example:
*/
this.values[0] = 1;
this.values[9] = 5;
/*
that is the hard way to do it though,
this is easier:
*/
this.values = {1,0,0,0,1,2,3};
/*
that will set an array with 7 values (0-6)
and can be called as so:
*/
this.newnumber = this.values[5];
/*
Meaning that this.newnumber would equal 2
*/
Mostly with big arrays you put them thru a for loop,
like in this rain example:
*/
// Rain script:
if (created) {
setarray this.rainx,100;
setarray this.rainy,100;
for (i=0;i<arraylen(this.rainx);i++;) {
/* arraylen(arrayname) <-- gives you the amount of indexes in the array.*/
this.rainx[i] = random(0,64);
this.rainy[i] = random(0,64);
}
}
if (playerenters||timeout) {
for (i=0;i<arraylen(this.rainx);i++;) {
// Shows rain:
showimg i+500,@.,this.rainx[i],this.rainy;
// Puts the rain above the player:
changeimgvis i+500,3;
// If the rain reaches the end of the screen it will repeat:
this.rainx[i]+=(this.rainx[i]>64 ? -64 : 0);
this.rainy[i]+=(this.rainy[i]>64 ? -64 : 0);
/*
if this:
this.rainx[i]+=(this.rainx[i]>64 ? -64 : 0);
looks weird, what it is, is a condition, if you look, the syntax is this:
(condition ? a : b)
if the condition is true than it goes to a otherwise it goes to b.
If it doesn't make sence im me we can talk about it.
*/
}
timeout=.05;
}


stomper_TK 03-05-2002 01:26 PM

Hey I started this fad about not knowing how to script right?

[edit]And I still don't get what that rain script means at all! Somoene make an example that a two year old could understand! Because I'm ****ing lost.. [/edit]

slick_soul 03-05-2002 02:00 PM

lol. That last post he did finished me off.

stomper_TK 03-06-2002 01:03 PM

jesbus.. HELP US PEOIPLES!

aim++ ramsey1337 ;)


All times are GMT +2. The time now is 06:05 AM.

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