- Home /
Does Scripting Jump exist? (How To use/write goto)
well I'm asking as if there's possibility to make this kind of jump or Must I wrap the random code in to function and call function like that?
jump start
// random code
if (true){
// change variables in random code a bit
jump to start
}
EDIT:
goto start;
gives me:
Assets/Scripts/CreateFloor.cs(102,38): error CS0159: The label `start:' could not be found within the scope of the goto statement
I couldn't find anykind of goto with google but today I've accidentally found goto with scripting and it helped me and showed me goto than I remembered what was mike saying
now my Q is how to use this goto as if I start placing anything I get no help so I'm kinda blind + goto is not in manual
Answer by Unitraxx · Mar 31, 2013 at 08:09 PM
try placing "start : " somewhere. This should be the label you jump to.
Answer by $$anonymous$$ · Mar 31, 2013 at 09:05 PM
In the goto statement, the you first must declare a label like this myLabel:
and then jump too is later in code like this goto myLabel;
however, this is a horrible coding practice, this should never be used in basic coding, use methods and loops instead.
I know but some times it solves me much headaches was always thinking how could I do that and why can't I
the reason you can't is because it makes the code incredibly hard to read and follow.
Classes are jumped to by calling there functions but classes are clearly defined and what they do is obvious and the key is that coded properly I shouldnt have to check a class declaration. Whatever your doing is obvious.
Time.Current() for example if you had that. I don't need to know, it's obvious what your retrieving. It's also built into the code what that function does or does not return. What values it does or does not change.
I can be confident that class functions arent screwing with variables outside their class definitions. I can't be confident your not jumping to code that changes variables and stuff so now I need to search through and find that code and figure out what it's actually doing.
Don't use goto. If your finding it a headache your doing it wrong.
The main problem is Goto is a crutch that prevents you from having to figure out a better more elegant way to code something that avoids goto and learning that is important.
You might one day write code that others will read because your coding together and they will hate you if you use goto.
You should learn now so you don't have to either have them hate you or else spend time then unlearning the use of goto and learning the right method to use to solve your problem you have now.
Looks like I have 2 gotos in my project (in one function) - could be coded out with an additional series of loop constraints and a bunch more break statements I guess, but I think it would make it less readable.
break and continue in deeply nested loops are far less obvious than goto in my opinion.
I guess I tend to use them to operations where scripting the while conditions would become meaninglessly complicated - it's usually to force a fail under complex circumstances from within 2+ nested loops that lend themselves to its use.
I note that there are also gotos in $$anonymous$$egafiers and a couple of other 3rd party things I use. Not dead yet then....
Answer by sparkzbarca · Mar 21, 2013 at 07:47 AM
edited:
My bad no direct jumping even if it does exist is a just terrible idea.
you just make a script and return to the script or dont leave start.
Oh I dunno, pretty sure I've never written a program that didn't end up with a Goto or 2 somewhere!
am @whydiidoit is it possible for unity scripting to make Goto?
I searched for Goto and couldn't find anything.
well that kind of scripting can give me an "multi dimentional functions" that I'd actually need much more to write than with Goto
I recall a Comp Sci lesson called 'Should the GoTo go, too?' and the conclusion was 'maybe'.
I've never seen a case where a goto was essential, but many where it was very convenient. I personally am ok within the Unity world to code around needing 'goto', but I do sometimes use it in other environments.
yeah ok but how to write it please I don't have a clue?
goto start;
gives me:
Assets/Scripts/CreateFloor.cs(102,38): error CS0159: The label `start:' could not be found within the scope of the goto statement
Your answer
Follow this Question
Related Questions
Audio Play Once 2 Answers
Script Efficiency 1 Answer
Script only makes character run forward 1 Answer
Character Not Rotating 0 Answers
My AI keeps flickering between stopping and moving. 1 Answer