Author Topic: I need help with a script.  (Read 1179 times)

Okay, there are two separate functions. In one function, I create a variable with two arrays - The player, and another player. But in the other function, I want to recall the second array (The other player) using a server command, but I can't figure out how to. Can anybody help with this? Thanks!

Code: [Select]
$pCt = -1;

function serverCmdsetupStuff(%client, %first, %second)
{
  $player[$pCt++] = findClientByName(%first).player;
  $player[$pCt++] = findClientByName(%second).player;
}

function serverCmdrecallStuff(%client, %num)
{
  messageClient(%client,'',"\c6"@$player[%num].client.name SPC $player[%num]);
}

something like that?

Actually, I kind of worded it terribly. Here's what my code looks like:
Code: [Select]
function serverCmdtest(%client, %text)
{
%name = %client.getPlayerName();
$var[%name,%text] = true;
}

As you can see in line 3, I placed both the name and the text in the same array. Can I still call both of them in a separate function, or should I remove one string because I messed up?

I think $var[*,text] should work, but I never had to do that so I'm not sure.

the "$" in front of variable names means its a global

globals can be used anywhere

Code: [Select]
$pCt = -1;

function serverCmdsetupStuff(%client, %first, %second)
{
  $player[$pCt++] = findClientByName(%first).player;
  $player[$pCt++] = findClientByName(%second).player;
}

function serverCmdrecallStuff(%client, %num)
{
  messageClient(%client,'',"\c6"@$player[%num].client.name SPC $player[%num]);
}

something like that?

Actually, I took what you said, and instead of using two arrays and the value being bool, I used only one array and made the value what the second array was. I haven't tested it yet, but hopefully it works...

Actually, I kind of worded it terribly. Here's what my code looks like:
Code: [Select]
function serverCmdtest(%client, %text)
{
%name = %client.getPlayerName();
$var[%name,%text] = true;
}

As you can see in line 3, I placed both the name and the text in the same array. Can I still call both of them in a separate function, or should I remove one string because I messed up?


It looks like what you are trying to do is to store data in an array, but right now you have the data being stored as part of the name.  Also, you cannot have multiple arguments in an array, such as $var[%arg1, %arg2], but you can have multiple words, such as $var[%arg1 SPC %arg2], but then you cannot export the array and execute it without getting a syntax error, since it is saved as "$vararg1 arg2" which has incorrect syntax.  Anyway, what I think you should do is have something more like $var[%someidentifyingterm] = %name TAB %text; However, if all you are trying to do is test to see if someone with a specific name has used that text in this servercmd, then you are doing it fine, minus the multiple argument array thing.


Also, you cannot have multiple arguments in an array, such as $var[%arg1, %arg2], but you can have multiple words, such as $var[%arg1 SPC %arg2], .
You can. Both of those compute to the exact same thing. $var%arg1_%arg2

Never put spaces in a Global Variable array name.


RULE 1
What does that have to do with this? His title isn't all that bad. Besides, it's coding help.