Graal Forums

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

falco10291029 02-20-2005 09:10 PM

for
 
I basically know how to use the new for function but I have a question.


It's supposed to replace the with command but I am not sure exactly how one is supposed to actually do a function with it, though setting variables i an do.

I think it is something like this:
NPC Code:

for (pl: players) {
pl.setlevel2(level,x,y);

}


But I am not sure if that's right. I ahve been trying it like that but my results are inconclusive, can someone tell me if this is right, and if not, the proper way to do it?

Gambet 02-20-2005 09:17 PM

I'll give you some examples, hopefully this helps:

NPC Code:

with (findnpc("NPC Name"))
with (allplayers[i])



NPC Code:

for (item: clientr.item)
for (i=0; i<allplayerscount; i++)



NPC Code:

setlevel2(level,x,y);
player.setlevel2(level,x,y);




I believe these are all the player-level manipulations you can do:

player.level - object, read only
player.x - floating point value
player.y - floating point value
player.z - floating point value

Evil_Trunks 02-20-2005 09:30 PM

Quote:

Originally Posted by falco10291029
I basically know how to use the new for function but I have a question.


It's supposed to replace the with command but I am not sure exactly how one is supposed to actually do a function with it, though setting variables i an do.

I think it is something like this:
NPC Code:

for (pl: players) {
pl.setlevel2(level,x,y);

}


But I am not sure if that's right. I ahve been trying it like that but my results are inconclusive, can someone tell me if this is right, and if not, the proper way to do it?

don't even bother reading Gambet's post, it's not helpful at all

you have it correct, you prefix the command/variable with the player's object

by default it uses player so these two commands are equal
NPC Code:
setlevel2(level,x,y);
player.setlevel2(level,x,y);



if you want to get a variable of another player, i think you should be able to figure it out, you have it correct in your example, but here's an example of getting a player's object then using it

NPC Code:
pobj = findplayer("Evil_Trunks");
pobj.hp = pobj.maxhp;
pobj.setlevel2(player.level,player.x,player.y);



it would heal Evil_Trunks to max hp, then bring him to wherever the active player is

in your example, you are getting each item of the "players" array, which contains an object for each player in the level

falco10291029 02-20-2005 09:35 PM

Thank you Evil_trunks for your help, Good to know I'm doing something right ;). And Also thanks for the examples of having it do something based on two players, I can now finmd my scripts that use multiple with or fors and the variable thiso.work and thiso.level=h.nw ect ect :).

Gambet 02-20-2005 09:35 PM

Actually, my post is helpful. I didnt give him the script myself, instead I showed some examples on how to use each of those commands correctly. He should be able to do the rest from there. Its the best way of learning, by viewing examples, instead of just scripting things for the person.

falco10291029 02-20-2005 09:44 PM

Not really, your post said I was wrong and that I should use with and the old for command. Also Evil_trunks did give me examples by showing the prefix commands and the example of setting another player's values through a different ones. Also i now know from that that IU dont need to use for in an instance like:

NPC Code:


for(pl: this.player) {
pl.client.string-=5000000;
}


Gambet 02-20-2005 09:48 PM

I didnt say your post was wrong. I was giving examples on how to use the with, for, and setlevel commands with the new engine. You shouldve picked up from there. If I needed to further elaborate, then I'm sorry. But Evil pretty much summed it all up.

falco10291029 02-20-2005 09:50 PM

Well I didnt need wioth examples i'm fine with that command You may have misread my only question was if I used that for command correctly and from your post it seemed like you were saying that it was only usable with the values you supplied.

Gambet 02-20-2005 09:52 PM

Ah, my mistake then.

ApothiX 02-21-2005 01:25 AM

Quote:

Originally Posted by falco10291029
It's supposed to replace the with command

It does not replace the with command, and it is called a for-each loop.

PHP Code:

for(ab) {
  
// Code


What it really does it cycle through an array, and set the value of b with the next index to a.

It is essentially the same as:
PHP Code:

for(i=0;i<b.size();i++) {
  
b[i];

  
// Code



falco10291029 02-21-2005 02:41 AM

Actually the for-each command can replace with, and the for loop cant without using with, so yes i believe it can, plus stefan said himself that it's meant to.

Lance 02-21-2005 02:43 AM

Quote:

Originally Posted by falco10291029
Actually the for-each command can replace with, and the for loop cant without using with, so yes i believe it can, plus stefan said himself that it's meant to.

Hint: It's not the foreach part that replaces the with. It's that line where you are accessing functions/variables of the player object.

falco10291029 02-21-2005 02:59 AM

yes I suppose it actually replaces for with combo if you need to use for-each.

What i mean by this is:

NPC Code:

for (pl: allplayers) {
if (pl.client.hp>1000) {
pl.chat="I am Hacking!";
sendtorc(pl.account @ "is Hacking");//I think i did that part right, not entirely sure though
}
}


replaces:
NPC Code:

for (i=0;i<allplayerscount;i++) {
with(allplayers[i]) {
if (strtofloat(#s(client.hp))>1000) {
setplayerprop#c, I am hacking!;
sendtorc #a is hacking!;
}
}
}


ApothiX 02-21-2005 05:22 AM

Quote:

Originally Posted by falco10291029
Actually the for-each command can replace with, and the for loop cant without using with, so yes i believe it can, plus stefan said himself that it's meant to.

It doesn't replace with, if it did, this would work:

PHP Code:

for(plallplayers) {
  
client.test "blah";


but it doesn't.

you still have to do:

PHP Code:

for(plallplayers) {
  
with(findPlayer(pl.account)) {
    
client.test "blah";
  }



You can also just aswell do:

PHP Code:

allplayers[index].account 

no need for a foreach loop at all.

falco10291029 02-21-2005 06:05 AM

NPC Code:

for(pl: allplayers) {

pl.client.test = "blah";
}


like that, no with.

ApothiX 02-21-2005 02:30 PM

Quote:

Originally Posted by falco10291029
NPC Code:

for(pl: allplayers) {

pl.client.test = "blah";
}


like that, no with.

exactly, you have to access the object directly, if it was a substitute for 'with', you would just have to do client.test = "blah";

falco10291029 02-22-2005 01:19 AM

Well then the prefix of pl or whatever then acts as a replacement for with.

Lance 02-22-2005 02:14 AM

Quote:

Originally Posted by falco10291029
Well then the prefix of pl or whatever then acts as a replacement for with.

Yes.

ApothiX 02-22-2005 03:04 AM

Quote:

Originally Posted by falco10291029
Well then the prefix of pl or whatever then acts as a replacement for with.

That is so redundant.

with() is what you use so you don't have to use the prefix.

falco10291029 02-22-2005 03:09 AM

Quote:

Originally Posted by ApothiX
That is so redundant.

with() is what you use so you don't have to use the prefix.

I personally find it easier to use the prefix.

Admins 02-22-2005 05:17 AM

The "with" command is kinda changing the environment - by default variables and functions without prefix are either mapped onto the current npc or the current player. With "with" you can change the current npc or current player, so that functions without prefix are mapped onto other objects, in old scripting engine this was the only way to warp another player because "setlevel2" is always warping the "current" player.
Only a few variables were accessible with prefix (players[index].x etc.) in the old engine. In the new engine everything is accessible directly, so you can access numeric attributes like "x" or "y", string attributes like "account" or "nick", built-in functions like "setlevel2" or "setani" or even script functions of other objects, e.g. StatsDatabase.addStatsForPlayer(player), if you declare a function as "public function".
So the with-command is not really needed anymore, but often very useful if you want to do a lot of operations on an object, also it can sometimes be faster, although some script optimizations are disabled inside with-blocks (because the lookup of this. numeric variables is changed, this is different to old scripting engine).

Python523 02-22-2005 02:58 PM

Quote:

Originally Posted by falco10291029
Well then the prefix of pl or whatever then acts as a replacement for with.

My. God. Learn to think like a computer scientist. It does not "replace" with.

allplayers is an object of some sort that acts as an array of all of the players online. By using the foreach syntax of with, you are merely just cycling through every element of that object array and setting each instance at a specific point in time to a specific player. There is no REPLACING. It is just another method to do it.

falco10291029 02-22-2005 10:28 PM

Quote:

Originally Posted by Python523
My. God. Learn to think like a computer scientist. It does not "replace" with.

allplayers is an object of some sort that acts as an array of all of the players online. By using the foreach syntax of with, you are merely just cycling through every element of that object array and setting each instance at a specific point in time to a specific player. There is no REPLACING. It is just another method to do it.

My. God. Learn to read. I said it acts as a replacement, not that it actually is one. I am aware that it is only an alternative, and that the with command still works.

By acting as a replacement (For those of you who don't know english, acting as means purposely having similar traits of such, but not actually being it) it means that you can use it as one, though it isn't necessary. Thank you for taking my post and messing it up with your *****ic "thinking". No, really.

ApothiX 02-22-2005 11:11 PM

Quote:

Originally Posted by falco10291029
My. God. Learn to read. I said it acts as a replacement, not that it actually is one. I am aware that it is only an alternative, and that the with command still works.

By acting as a replacement (For those of you who don't know english, acting as means purposely having similar traits of such, but not actually being it) it means that you can use it as one, though it isn't necessary. Thank you for taking my post and messing it up with your *****ic "thinking". No, really.

My. God. Learn GScript. It is NOT replacing with at all. The default way to do it is with prefixes, therefor, with is what is doing the replacing. It is like internet-shorthand, you don't replace 'u' with 'you', you replace 'you' with 'u'.

falco10291029 02-22-2005 11:13 PM

Quote:

Originally Posted by Apothix
My. God. Learn GScript. It is NOT replacing with at all. The default way to do it is with prefixes, therefor, with is what is doing the replacing. It is like internet-shorthand, you don't replace 'u' with 'you', you replace 'you' with 'u'.

Holy crap did you even read my post? Obviously not and I'll leave you to figure out why you couldn't possibly have by looking at your post and mine just before it. (Hint: look at the bold part)

ApothiX 02-22-2005 11:14 PM

Quote:

Originally Posted by falco10291029
Holy crap did you even read my post? Obviously not and I'll leave you to figure out why you couldn't possibly have by looking at your post and mine just before it. (Hint: look at the bold part)

Obviously I read your post if I was explaining how you were wrong about stating that prefixes are the replacement.

Think before you post.

falco10291029 02-22-2005 11:18 PM

Quote:

Originally Posted by Apothix
Obviously I read your post if I was explaining how you were wrong about stating that prefixes are the replacement.

Think before you post.

I find this funny. You'll note that my post says that i know it isn't.

Think.

Lance 02-22-2005 11:57 PM

Quote:

Originally Posted by Python523
My. God. Learn to think like a computer scientist. It does not "replace" with.

allplayers is an object of some sort that acts as an array of all of the players online. By using the foreach syntax of with, you are merely just cycling through every element of that object array and setting each instance at a specific point in time to a specific player. There is no REPLACING. It is just another method to do it.

I can tell that your 'It' is referring to the foreach loop. We've kinda already established that part.

Quote:

Originally Posted by ApothiX
My. God. Learn GScript. It is NOT replacing with at all.

It looks like your 'It' is referring to the new method of accessing object properties. If so, your statement is incorrect.

Quote:

The default way to do it is with prefixes, therefor, with is what is doing the replacing.
'Default'? Another vague 'it'?

Quote:

It is like internet-shorthand, you don't replace 'u' with 'you', you replace 'you' with 'u'.
What? Do you not understand the definition of the word 'replace'? Your vague and inconsistent explanations and examples would seem to suggest so.

ApothiX 02-23-2005 12:56 AM

Quote:

Originally Posted by falco10291029
I find this funny. You'll note that my post says that i know it isn't.

Think.

Show me where it says this?

falco10291029 02-23-2005 02:22 AM

Here:
Quote:

I am aware that it is only an alternative, and that the with command still works.
and also here:
Quote:

By acting as a replacement ... it means that you can use it as one, though it isn't necessary.
Again, read.

ApothiX 02-23-2005 04:10 AM

Quote:

Originally Posted by falco10291029
Here:

and also here:

Again, read.

You are still calling it a replacement, which it is not

falco10291029 02-23-2005 04:43 AM

Quote:

Originally Posted by ApothiX
You are still calling it a replacement, which it is not

How am i calling it a replacement? I specificallyt am saying that it isn't and that it is merely an alternative.

ApothiX 02-23-2005 02:35 PM

Quote:

Originally Posted by falco10291029
How am i calling it a replacement? I specificallyt am saying that it isn't and that it is merely an alternative.

Oh, I don't know.. Perhaps it was the whitty-as-hell definition you gave

Admins 02-23-2005 02:51 PM

WHO cares if it is a replacement or an alternative. You can do things with prefixes that before where only possible with the with command.


All times are GMT +2. The time now is 06:32 PM.

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