Help with Redirect script

From what I understand about writing a redirect script, in this case for Germanium, all that's really required for it to work is:

Initialize:
int main(){
redirectGermanium();
}

But I wanted to spice mine up a little bit. It compiled just fine, and it runs fine, but it doesn't redirect any Germanium. Was wondering if someone could take a look and tell me if it's my "spice" code that's causing it, or if it's something else. Here's the complete code:

Initialize:
int main() {
int done=1;
string germ = Germanium;
while(!done) {
// If Germanium exists, redirect to Attacker
if (fileExists(germ) == true) {
redirectGermanium();
}
// Else if no Germanium exists, end attack
else if (fileExists(germ) == false) {
done=1;
}
}
}

I'm still trying to wrap my head around the minute limitations of what can be combined into a single script, and what cannot. Also, I'm not even sure while statements can even be used. This is the first script I've tried to compile.

Please don't flame me too hard for my horrible scripting! =)

Problem in the loop

RazorChrist,

There are a couple of problems that I can see with your code. The first is that you initialize the variable "done" to be 1. Then your while loop tests for not "done", so the code in the loop never actually executes because a while loop will execute the code inside only while the value of the test statement is true (or 1 as the case may be). If you were to change the while loop to be: "while (done) {...}" then it would execute the code inside. Then to exit the while loop you would merely need to change the value of "done" to 0.

The second problem is that the initialize function is only called once before the attack (or redirection) actually starts. So, if you were to change the while statement to what I suggested it would simply cause the script to loop until it hits the maximum number of operations or you delete the file "Germanium." Which brings me to the next error.

When using the function fileExists(string file_name) you want to pass it a string that represents the files name. When you declared the string type variable "germ" you set its value to be Germanium. This may compile, but I'm not sure if it would insert the correct value into the variable germ. You should probably change the initialization of the variable germ to look something like this: 'string germ = "Germanium" ' Make sure that the word Germanium is inside quotation marks so that the compiler knows that it is a string and not the name of another variable.

From the looks of your code I'm guessing that you're trying to make it so that it will stop the attack if delete the file "Germanium." If this is the case you would want to move your this code to the "Continue" portion of the redirect script. You would then delete while loop and only leave the variable "germ" and the if structure. You would not need to write a loop because the "Continue" portion of the code is called each time the script tries to attack. If wanted the redirect to stop when the file was deleted you would need to use a function like the attack function "cancelAttack()" inside the if statement, however I'm not sure if that function will work in a redirect script.

In conclusion, the main reason your script will not redirect any germanium is that the "redirectGermanium()" function is never getting called due to the error in the while loop. I hope this helped. If you need any more help I'd be happy to help you.

If I made any mistakes or false assumptions someone please correct me.

-----------------------------------------
Give a man a fish and he eats for a day. Teach him how to fish and you get rid of him all weekend.

A few pointers

There are a few things wrong with this that aoi did not point out.

1) The redirectGermanium() function automatically will get all the germanium for you, you do not need to try and check if there is still some left.

2) Germanium is not stored in a file called "Germanium", it exists as a commodity, so checking fileExists("Germanium") would not tell you if they still have Germanium commodities left.

3) I have never tested using ints ( 0 and 1 ) as the condition for a loop, it may work but it would be more clear (and I know this works) if you used booleans, for example:
boolean done = false;
while(!done) {
... do stuff ...
if(someCondition) {done = true;}
}

-TTJ

(Im in ur compilerz lolin' ur codez !)

Thanks for all the help guys.

Thanks for all the help guys. I finally just got frustrated and used the basic redirectGermanium() and nothing else, and it seems to working fine. I'll work on fancier scripts later down the road.

PSP = Phat 5.00 m33-6 w/ 1.50 Kernel Addon
WII = Softmodded v3.3u w/ Homebrew Channel + IOS249
Wii Dev Projects: