
elfege
USA
Asked
— Edited
Has anyone figured out way to get the goto() function to work with variable so it can goto the last defined loop such as this :
$lastLoop = ""
:loop1
$last = "loop1"
left(200, 0)
sleep(100)
print($last)
goto($last)
this would allow to have the equivalent to calling a function and resuming the current loop after its execution. It would prevent me from using too many scripts and avoid lots of redundancies. My project currently has 50 scripts so I'm trying to find a way to shrink this number.
Thats a good question. No to side track, but always wondered about how many scripts could be run before things kinda run outta steam. My project only has about 6 or 7 scripts and it seems to seem to cause disconnects alot of times,
I think you are going to need to do something more like this...
forgive me if it isn't working code. I haven't been in the scripting world for quite a while and it may not be the exact syntax, but you get the idea.
Not that this next part is to the first question, but hopefully answers the other concern mentioned... Also, I try to write code so that one script does one thing and is called by other scripts when that function is needed. This allows you to call the same script from multiple other scripts (reusable) when that function needs to be performed. Because of this, I have projects with over 100 scripts in them without seeing any performance issues. Multiple of these scripts are running at the same time in their own threads without seeing performance issues.
That isn't possible because the compiler preprocesses the opcodes for things like goto, Return, if, elseif, if, etc...
A compiler is a process that runs on code to convert it into a structured logical path and logical elements which the cpu or virtual processor understands. Without this process, the "scripting" language would have to evaluate the whole script for each line of execution. That would cause performance issues in the hundreds of times less.
Ezscript and all languages that compile to opcodes are effecient for that reason. Without an opcodes preprocesser, I doubt your cpu would be able to run more than 3 or 4 scripts at once.
@RoboHappy I am going to say the way you are coding or your power source is what is causing your disconnects... As David mentioned, proper or better scripting techniques would probably eliminate your problem... I run multiple scripts all the time with zero performance degradation and certainly no disconnects...
As CochranRobotics mentioned, offhand the only way I can think of would be to use a variable to run through an IF-ElseIF combination. For example:
The closest there is to automatically returning from where you left off is to use a CommandControl statement. To eliminate redundancy you could set a variable to a portion of a script and use an If-Elseif statement to go to that portion of the script upon arrival, after using a CommandControl. For example:
If you're interested, I've developed this idea (possibly to a ridiculous degree) to include a form of pseudo parameter passing and variable localization. I have uploaded a project called HTML Reader which uses these principles as part of a project to read certain portions of web pages.
@Richard R... Yes I would have to agree, thats what I figured it be as well. Since I am still learning much about Ezb script writing, I have ways to go ( And I thought my Basic Stamp was hard). Im trying to run the Speech req,rgb animator,2 drive wheels,use 5 ultrasonic sensors,1 IR sensor, the camera,the Wii controller, 8 servos (for arms) so far. I dont know if thats alot or pretty normal really.
RoboHappy, post your project - everything that you're doing is fine. I suspect the number of IR sensors and Ultrasonic sensors is the issue with disconnects.
@RoboHappy One of the things I have found that will cause a disconnect is recursive calls to scripts. That is to say, scripts which call other scripts in such a way that a script ends up effectively calling itself. It usually takes a few seconds for it to happen as the call stack builds up to an overflow condition. They can also be tricky to track down since they can take unexpected routes. Also, it doesn't happen every time since the program flow can be different under different conditions.
For example, using CommandControl statements, Script A calls Script B, which, in turn, calls Script C. But Script C calls Script A, which calls B again, which calls C, and so on and on until the system runs out of memory which causes the disconnect. I'm not sure why it disconnects, but that seems to be the result.