|
Foam Novice
Joined: 08 Nov 2000 Posts: 44 Location: Australia
|
Posted: Thu Apr 04, 2002 1:55 pm
Where to put code that is refered back to often? |
i have 14 aliases that have 29 lines of code in each, 25 of those lines are exactly the same in each alias. My problem is this, every time i want to make a improvement, i have to change the code in all 14 aliases each time, which is very annoying when debugging. So i decieded to try sticking the 25 lines of the code that is the samein each alias into a variable that each alias could call upon, but ive run into a problem. At one stage two of these aliases are called in a row, so 58 lines get sent to the mud at once now that ive put the code in a varible, this of course spams me off the mud. I'm not sure what the proper approach is to manage this situation, would somebody more experienced in programming be able to point out what im supposed to be doing?
tnx for your time |
|
|
|
Toetag Magician
Joined: 10 Oct 2000 Posts: 356 Location: USA
|
Posted: Thu Apr 04, 2002 2:09 pm |
could you use IF statements with a control variable? then set the trigger to set the variable and call the alias.
ie:
IF x=1 run this
IF x=2 run that
IF X=3 run something else
etc
Killing a fly on a friends forhead may not be overkill, use a hatchet to make sure the job is done. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Thu Apr 04, 2002 5:49 pm |
Instead of putting the identical lines of code in a variable, put them in another alias.
#AL identical25 {lineI1;lineI2;...lineI25}
Your existing aliases can then call this where needed:
#AL existingA {identical25;lineA1;lineA2;lineA3;lineA4}
#AL existingB {lineB1;identical25;lineB2;lineB3;lineB4}
#AL existingC {lineC1;lineC2;lineC3;lineC4;identical25}
Since you were able to place all 25 identical lines in a single variable I'm assuming they will be used in a single block no matter where they come in the existing aliases.
LightBulb
All scripts untested unless otherwise noted |
|
|
|
heidi Newbie
Joined: 04 May 2002 Posts: 1
|
Posted: Thu Apr 04, 2002 6:06 pm |
I'll take a stab at this since I think I have my head around what you are trying to accomplish. I assume you are doing something like:
#var Test {#show 1;#show 2}
#alias {a} {#Exec @test}
The root of the problem is why the alias is getting called twice. We would need further details on what is happening to figure this out. What is odd to me is that it didn't spam 58 lines when the code was in the 14 discrete aliases.
But, following is an idea for how to stop one alias for accidently calling another:
#var Test {#var Running 1;#show 1;#show 2}
#alias {a} {#if {@Running} {} {#Exec @test;#var Running 0}}
This type of code ensures that the alias will only run if it or another instance that uses the "Temp" variable isn't already in use. For instance, the following alias would only exec the variable once:
#alias {b} {#if {@Running} {} {#Exec @test;a;#var Running 0}}
Hope that helps.
El_Dickman |
|
|
|
|
|