Graal Forums

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

WanDaMan 09-18-2002 02:43 PM

Help
 
hey i dont understand Variables (cant spell it) and what the do. i went on your site projectshifter and i got to the variables bit and i just didnt understand what they do?can some one help me learn them?

emortylone 09-18-2002 11:00 PM

Ah, they are VERY useful. They keep track of numbers. For example:
NPC Code:

if (created)
{ this.hit=0;}

if (washit)
{ this.hit=this.hit+1;
hit();
}

function hit()
{ setcharprop #c,#v(this.hit);}


that makes this.hit go up ONE time everytime it was hit. And it will display it via #c as how many hits have happened. This.vars are ONLY for NUMBERS, no data can be stored in them. But I've done things like this:
NPC Code:

if (created)
{ this.dist=abs(npcs[1].save[1]-x)-abs(npcs[1].save[2].y);}


Something like that, i'm not exactly sure b/c I'm at school :P and i don't have much time. BUT I had a central NPC set npcs[1].save[1 and 2] to it's x and y. So this.dist was the distance it was from the central point. It was useful because I was making a clock that rotated around the middle, so I didn't have to code everything to be so far from the central point, I could move it out to ANY distance I wanted and it would still make a circle around that middle point. the radius changed, but the middle point didn't :D Try some stuff... I'll get you some examples if I get home in time.
---Shifter

WanDaMan 09-19-2002 03:01 PM

i get..
 
hey i get the top one but not the bottom one :/ i think it has something to do with the save and stuff in it
the top 1 is easy to understand and i think i can get the hang of it to
Quote:

if (created)
{ this.hit=1;}

if (washit)
{ this.hit=this.hit+3;
hit();
setcharprop #c,You have hit it #v(this.hit) Times;
}

function hit()
{ setcharprop #c,#v(this.hit);}
i think that might work i dunno i am guessing here XD
--snakeandy

R0b1n-NPC 09-19-2002 04:51 PM

do not format like shifter because his formatting is teh suck :| (no offence)

emortylone 09-19-2002 11:08 PM

w00t WooT! USe my scripting style, it's going Revolutionary! people use it :P Yes, I like my scripting, just b/c you don't doesn't mean you are allowed to become jealous ;) But obviously you're not sure how to use functions :P If you put: something(); it means that it will jump to the part of the scripted marked:
function something()
and perform all actions under it. I always use return; at the end if it isn't looping for teh hell of it. What you did would have it set it to what you said, then it would set to mine, so it then becomes inefficient b/c you are setting it twice and one will be erased too fast to read it?
---Shifter

R0b1n-NPC 09-19-2002 11:33 PM

i think functions should have custom variables that can only be used inside the functions, e.g.

PHP Code:

if (playerenters) {
  
killplayer(#a,Hahah you suck);
}

function 
killplayer(account,message) {
  
with (getplayer(account)) {
    
playerhearts=0;
    
say2 message;
  }


that would be teh 1337 :D

Dach 09-20-2002 02:20 AM

Quote:

Originally posted by R0b1n-NPC
i think functions should have custom variables that can only be used inside the functions, e.g.

PHP Code:

if (playerenters) {
  
killplayer(#a,Hahah you suck);
}

function 
killplayer(account,message) {
  
with (getplayer(account)) {
    
playerhearts=0;
    
say2 message;
  }


that would be teh 1337 :D

Great idea, but this has been asked for since functions were added to graalscript long ago (like 3 years or something).

R0b1n-NPC 09-20-2002 02:44 AM

*realises this*

but it SHOULD be added.

RavenTelvecho 09-20-2002 04:13 AM

Quote:

Originally posted by R0b1n-NPC
i think functions should have custom variables that can only be used inside the functions, e.g.

PHP Code:

if (playerenters) {
  
killplayer(#a,Hahah you suck);
}

function 
killplayer(account,message) {
  
with (getplayer(account)) {
    
playerhearts=0;
    
say2 message;
  }


that would be teh 1337 :D

like php ^_^

R0b1n-NPC 09-20-2002 04:27 AM

Exactly!

emortylone 09-20-2002 08:01 AM

WTF is the point?? If you can ONLY set them in functions??? Just have the variables ONLY be changed by them then =/
---Shifter

Dach 09-20-2002 08:39 AM

You'd need an actual return command then, like

return account,message;

emortylone 09-20-2002 09:18 AM

Um, this.vars work regardless of where. then ONLY have functions edit them x.X!
---Shifter

Dach 09-20-2002 09:36 AM

Shifter, what's your point? Of course there is a way to work around not being able to pass strings/variables to functions, but the point is that being able to do so would greatly increase the functionality of functions...

Falcor 09-20-2002 09:51 AM

Function arguments, it was suggested by me and a few other people long long time ago, yet never added, Some problem that graal isn't too object-orientated. *shrugs*


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

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