Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sdgd · Mar 20, 2013 at 08:37 AM · c#jump

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Unitraxx · Mar 31, 2013 at 08:09 PM

try placing "start : " somewhere. This should be the label you jump to.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Unitraxx · Mar 31, 2013 at 09:13 PM 0
Share

Converted it to an answer.

avatar image
2

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sdgd · Apr 01, 2013 at 05:57 AM 0
Share

I know but some times it solves me much headaches was always thinking how could I do that and why can't I

avatar image sparkzbarca · Apr 01, 2013 at 11:52 PM 0
Share

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.

avatar image sparkzbarca · Apr 01, 2013 at 11:54 PM 0
Share

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.

avatar image whydoidoit · Apr 02, 2013 at 12:03 AM 2
Share

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....

avatar image
0

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.

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Mar 21, 2013 at 08:02 AM 1
Share

Oh I dunno, pretty sure I've never written a program that didn't end up with a Goto or 2 somewhere!

avatar image sparkzbarca · Mar 21, 2013 at 08:10 AM 0
Share

what do you write in assembly lol

avatar image sdgd · Mar 21, 2013 at 10:07 AM 0
Share

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

avatar image DaveA · Mar 31, 2013 at 07:53 PM 0
Share

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.

avatar image sdgd · Mar 31, 2013 at 07:56 PM 0
Share

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
Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges