eska
2012-03-19 17:42:57
I'm making a monkey thiever script, and making sure that it can escape the prison by itself.
LockPickJailDoor picklock the door and make sure that it successfully picklocked it with various fail safe. I want it to try again if it failled (which is why there is a loop there. A simple if statement isn't enough.
Now as you can see, this code compiles, it works, but it does alot of instruction. It waste ressources. My bad, it doesn't, because it waits for the return value of LockPickJailDoor to continue looping.
I know some of you will tell me: Put a wait in there like this. Problem solved!
But no… that's not fixing a problem, thats just a work around in my opinion. I want a real solution.
My programming teacher would burn me at the stake if I gave him a solution like this.
Is there a way to avoid this problem?
Right now I'm thinking about adding recursivity in the LockPickJailDoor function so that when it fail to lockpick, we give up and logout, or if it is succesfull, we proceed with escaping the prison.
LockPickJailDoor picklock the door and make sure that it successfully picklocked it with various fail safe. I want it to try again if it failled (which is why there is a loop there. A simple if statement isn't enough.
MarkTime(t);
repeat
until (TimeFromMark(t) > 6000) or LockPickJailDoor;
Now as you can see, this code compiles, it works,
I know some of you will tell me: Put a wait in there like this. Problem solved!
MarkTime(t);
repeat
Wait(1000 + Random(500));
until (TimeFromMark(t) > 6000) or LockPickJailDoor;
But no… that's not fixing a problem, thats just a work around in my opinion. I want a real solution.
My programming teacher would burn me at the stake if I gave him a solution like this.
Is there a way to avoid this problem?
Right now I'm thinking about adding recursivity in the LockPickJailDoor function so that when it fail to lockpick, we give up and logout, or if it is succesfull, we proceed with escaping the prison.