Author Topic: How to make this script?  (Read 6196 times)

Yup. The %avatar is unneeded in what you've scripted, but that'll work none the less. What you should do is change the $var to %avatar, and change the schedule to schedule(5000,0,AvatarCycle,%avatar);
so it should be this?? I have a feeling that "%avatar++;" should be changed back to "$var;"
Code: [Select]
function AvatarCycle(%avatar)
{
   %avatar++;
   if(%avatar > 3)
      %avatar = 1;
   AvatarGui.Clickfav(%avatar);
   Avatar_done();
   schedule(5000, 0, AvatarCycle, %avatar);
}
I changed all the $var's into %avatar's. Like you said,
You guys forgot to set schedule to a variable so the loop can be exited with the cancel function. It seems like something that'd be nice to stop every once in a while.
At this point im confused and I'm 99.9% sure I did something wrong because I changed all the $var's into %avatar's.
This may seem obviously wrong to you guys but im really a newbie to this scripting thing. Sorry!
« Last Edit: July 16, 2014, 09:24:54 PM by Naked Human »

That function will work fine. What $trinick is saying is a way to stop the schedule, like changing the schedule to $CycleSched=schedule(5000,0,AvatarCycle,%avatar); so that way you can do cancel($CycleSched); and it'll stop looping the script.

That function will work fine. What $trinick is saying is a way to stop the schedule, like changing the schedule to $CycleSched=schedule(5000,0,AvatarCycle,%avatar); so that way you can do cancel($CycleSched); and it'll stop looping the script.
Hmmm... Maybe if I get more advanced in coding I could make a keybind that could turn it on and off!
For now I will keep it like this. So now I just need to know how to activate the script itself. Do I just type it into the console?

If you want you can add the ability to cancel the function in the script, like a toggle, you can do this by setting a separate global variable ($CycleOn) equal to 1 if the function is on, then at the end of the function you can add an if statement, checking to see if the that variable == 1, then setting it equal to zero and canceling $CycleSched.

If you want you can add the ability to cancel the function in the script, like a toggle, you can do this by setting a separate global variable ($CycleOn) equal to 1 if the function is on, then at the end of the function you can add an if statement, checking to see if the that variable == 1, then setting it equal to zero and canceling $CycleSched.
That's very useful. But I'm going to just add more to this function later on and add a keybind. I guess that's the easiest way to activate it and deactivate it instead of writing in the console manually.

-accidentally quoted myself-
« Last Edit: July 16, 2014, 09:51:22 PM by Naked Human »

Here's how:
Code: [Select]
if(!$avatarCycler)
{
$remapDivision[$remapCount] = "Name of the section of the controls list";

$remapName[$remapCount] = "Name of keybind";
$remapCmd[$remapCount] = "Name of the function";
$remapCount++;

$avatarCycler = 1;
}

What Headcrab Zombie is trying to say works too. I told you to use a global variable because it'd be easier to understand and there's not a huge benefit to using a local variable in this situation aside from saving the variable name. Since you have a schedule running constantly it'll always be in memory anyway, so you're not saving any memory by keeping it as part of the schedule, you're just putting it somewhere else.

It doesn't matter if you don't understand the stuff about memory, it's not too important right now. What he wants you to do is change $var to %avatar. This normally wouldn't work because variables that start with % get deleted at the end of the function. However, schedule is a special function that allows you to pass arguments to the function when you call it. So, when your schedule calls the function you can pass the current value of %avatar, have it run through the code, and then it'll schedule the function to be called again with the next variable.

What I was saying you should do is just add $AvatarCycleSchedule = before schedule(5000, 0, AvatarCycle, %avatar);. This will let you stop it manually in console with cancel($AvatarCycleSchedule);. Aside from that, you've done everything right! Good job.

Here's how:
Code: [Select]
if(!$avatarCycler)
{
$remapDivision[$remapCount] = "Name of the section of the controls list";

$remapName[$remapCount] = "Name of keybind";
$remapCmd[$remapCount] = "Name of the function";
$remapCount++;

$avatarCycler = 1;
}

At least try to explain it, Crysist.

What Headcrab Zombie is trying to say works too. I told you to use a global variable because it'd be easier to understand and there's not a huge benefit to using a local variable in this situation aside from saving the variable name. Since you have a schedule running constantly it'll always be in memory anyway, so you're not saving any memory by keeping it as part of the schedule, you're just putting it somewhere else.

It doesn't matter if you don't understand the stuff about memory, it's not too important right now. What he wants you to do is change $var to %avatar. This normally wouldn't work because variables that start with % get deleted at the end of the function. However, schedule is a special function that allows you to pass arguments to the function when you call it. So, when your schedule calls the function you can pass the current value of %avatar, have it run through the code, and then it'll schedule the function to be called again with the next variable.

What I was saying you should do is just add $AvatarCycleSchedule = before schedule(5000, 0, AvatarCycle, %avatar);. This will let you stop it manually in console with cancel($AvatarCycleSchedule);. Aside from that, you've done everything right! Good job.
Thanks! I will that to the script just in case. Thank you everyone without you guys I would have not done this script :'D.
Here's how:
Code: [Select]
if(!$avatarCycler)
{
$remapDivision[$remapCount] = "Name of the section of the controls list";

$remapName[$remapCount] = "Name of keybind";
$remapCmd[$remapCount] = "Name of the function";
$remapCount++;

$avatarCycler = 1;
}
Interesting, I'll play around with it and see if it works, Thanks!

Thank you everyone without you guys I would have not done this script :'D.

The sole reason Coding Help exists.

At least try to explain it, Crysist.
Sorry, I didn't know how. I just searched for it in another add-on, I'll try my best to explain it.

if(!$avatarCycler) checks to see if the global variable that we set equal to one has been set to one. We only set it to one once we added the keybind so it checks to see if the keybind is already there.

All the keybinds and their divisions are set to a global variable. One for their division or section $remapDivision[$remapCount], one for the keybind's name $remapName[$remapCount], and one for the function that keybind calls $remapCmd[$remapCount].

Each variable is numbered for each section so the game knows which command goes under which section. After the keybind is set, the global variable for the number at the end of the keybind is increased $remapCount++; so the next keybind can have its own section.

Square brackets at the end of variables allows you to add a number to the end of it, because you cant combine a variable and number like %variable%n = "1";, you have to put it in brackets like %variable[%n] = 1;, if %n = 4; then variable's name would end up as %variable[4].

Code: [Select]
if(!$avatarCycler)
{
$remapDivision[$remapCount] = "Name of the section of the controls list";

$remapName[$remapCount] = "Name of keybind";
$remapCmd[$remapCount] = "Name of the function";
$remapCount++;

$avatarCycler = 1;
}

Square brackets at the end of variables allows you to add a number to the end of it, because you cant combine a variable and number like %variable%n = "1";, you have to put it in brackets like %variable[%n] = 1;, if %n = 4; then variable's name would end up as %variable[4].

Square brackets allow for more than just numbers, and  if you have %variable[%n] and %n=4; it'll come out as %variable4 not %variable[4]

Square brackets allow for more than just numbers, and  if you have %variable[%n] and %n=4; it'll come out as %variable4 not %variable[4]
Yeah, I wasn't exactly sure of that part. Can't you still reference it as %variable[4] even if it is really named %variable4?