• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
tom_mai78101

Goto: How should I work the code out?

7 posts in this topic

Here's a[size=6] [color=#006400][b][u]Java pseudo-code[/u][/b][/color] [/size]I'm working on shown below:

[source lang="java"]public void someFunction(//Some parameters) {
//some boolean flags here.
switch (p.orientation) {
case VERTICAL:
if (booleanFlag1){
if (booleanFlag2){
//Some other codes.
goto Label;
}
//Some codes
}
else if (booleanFlag3){
if (booleanFlag4){
//Some other codes.
}
//Some codes
}
reflectResponse();
break;
default:
return;
}
Label:
//Some more codes... (required)
}[/source]

I'm very tempted to use "goto" in Java, but as always, goto isn't allowed because of said issue. I will digress from that.

I only know from [url="http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html"]Java doc here[/url] that said "break" keyword works for for...loop, do...while..., and switch...case... only. Anything I can do?
0

Share this post


Link to post
Share on other sites
Why can't you do this:
[CODE]
public void someFunction(//Some parameters) {
//some boolean flags here.
switch (p.orientation) {
case VERTICAL:
if (booleanFlag1){
if (booleanFlag2){
//Some other codes.
}
else if
{
//Some codes
}
}
else if (booleanFlag3){
if (booleanFlag4){
//Some other codes.
}
//Some codes
}
reflectResponse();
break;
default:
return;
}
//Some more codes... (required)
}
[/CODE]
This does the same thing as your code, but doesn't use a goto statement. Unless there is something I'm missing?
1

Share this post


Link to post
Share on other sites
[quote name='tom_mai78101' timestamp='1349339128' post='4986685']
Here's a[size=6] [color=#006400][b][u]Java pseudo-code[/u][/b][/color] [/size]I'm working on shown below:

[source lang="java"]public void someFunction(//Some parameters) {
//some boolean flags here.
switch (p.orientation) {
case VERTICAL:
if (booleanFlag1){
if (booleanFlag2){
//Some other codes.
goto Label;
}
//Some codes
}
else if (booleanFlag3){
if (booleanFlag4){
//Some other codes.
}
//Some codes
}
reflectResponse();
break;
default:
return;
}
Label:
//Some more codes... (required)
}[/source]

I'm very tempted to use "goto" in Java, but as always, goto isn't allowed because of said issue. I will digress from that.

I only know from [url="http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html"]Java doc here[/url] that said "break" keyword works for for...loop, do...while..., and switch...case... only. Anything I can do?
[/quote]
[list=1]
[*]You cannot use goto in Java.
[*]If you want to execute some code _only_ in the VERTICAL case when booleanFlag1 and booleanFlag2 are both true, don't do it this way. This is what you're trying to do, right? Instead, put this code in a separate function or method and call it inside the second `if` clause.
[/list]
1

Share this post


Link to post
Share on other sites
[quote name='RulerOfNothing' timestamp='1349340025' post='4986689']
Why can't you do this:
<snip>
This does the same thing as your code, but doesn't use a goto statement. Unless there is something I'm missing?
[/quote]

If both "booleanFlag1" and "booleanFlag2" are true, I need to execute code in "booleanFlag2" and then execute code in "booleanFlag1". So, the extra "else if" would not be the correct way.

[quote name='thok' timestamp='1349340478' post='4986693']

[list=1]
[*]You cannot use goto in Java.
[*]If you want to execute some code _only_ in the VERTICAL case when booleanFlag1 and booleanFlag2 are both true, don't do it this way. This is what you're trying to do, right? Instead, put this code in a separate function or method and call it inside the second `if` clause.
[/list]
[/quote]


1. I understand that. Hence I was asking if there are any alternatives.
2. It's not just VERTICAL case, there are other more cases. And no, it's not. I wanted to execute codes when booleanFlag1 and booleanFlag2 is true, but skip the code in booleanFlag1 and the rest of the code before the "Label". If booleanFlag2 is not true, continue to execute code in booleanFlag1, and call on reflectResponse() before continuing to execute more code.


[quote name='Ashaman73' timestamp='1349343262' post='4986702']
In your pseudocode just exchange [i]goto [/i]through [i]break[/i], that's it.

Longer answer: break will [i]break [/i]from the current for/while/switch statement, regardless if it is embedded itself in an other non-loop/switch statement, like an if-statement.
[/quote]

You mean, "break <label>"? I googled it, and it turns out this is an actual Java code. [url="http://geekycoder.wordpress.com/2008/06/25/tipjava-using-block-label-as-goto/"]Haven't seen this before.[/url] Thanks! :D
0

Share this post


Link to post
Share on other sites
[quote name='tom_mai78101' timestamp='1349344825' post='4986706']
You mean, "break "? I googled it, and it turns out this is an actual Java code. Haven't seen this before. Thanks! :D
[/quote]
Yes, you can label a loop (write it before the loop starts), but in your case you just need break; (without label).
0

Share this post


Link to post
Share on other sites
[quote name='tom_mai78101' timestamp='1349344825' post='4986706']


View PostRulerOfNothing, on 04 October 2012 - 06:40 PM, said:
Why can't you do this:

This does the same thing as your code, but doesn't use a goto statement. Unless there is something I'm missing?

If both "booleanFlag1" and "booleanFlag2" are true, I need to execute code in "booleanFlag2" and then execute code in "booleanFlag1". So, the extra "else if" would not be the correct way.
[/quote]
If you could use goto like in your first example, then the code in booleanFlag1 would be skipped.
1

Share this post


Link to post
Share on other sites
[quote name='RulerOfNothing' timestamp='1349348492' post='4986718']
If you could use goto like in your first example, then the code in booleanFlag1 would be skipped.
[/quote]
Yes, that would be true. I'm sorry for being mistakened. :(
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0