Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Is this an AGK Bug

Author
Message
aviles22
10
Years of Service
User Offline
Joined: 1st Dec 2013
Location: New Jersey, USA
Posted: 19th Mar 2014 22:18
I had a problem in my AppGameKit game that took me hours to figure out!

My Example:

function one
if difficulty = 1
goto skip
endif
skip:
endfunction


function two
if difficulty = 2
goto skip
endif
skip:
endfunction

The problem I had was that the goto skip command was jumping from function one to the skip: label in function two.

In my past experience with basic or even C++ a Goto label is not global outside of other functions therefore I never worried about naming them duplicate outside of the same function.

I guess for now I will totally avoid duplicating label names anywhere in my program!
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 19th Mar 2014 22:42
An even better idea is never to use goto!

-- Jim - When is there going to be a release?
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 19th Mar 2014 23:08
I don't use GOTO and GOSUB either. All function based.

JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 20th Mar 2014 00:41 Edited at: 20th Mar 2014 00:44
There aren't many cases where a goto may be used. They can have a role in compilers (the only time I've used them in the last 30 years) but otherwise they can cause horrible consequences. It's an unconditional jump that can leave loads of stuff on the stack or heap.

The code above is a signpost to the disasters that await!

The answer to the question as whether it's a bug is yes - but it's not an AppGameKit bug - it's just not very good programming.

-- Jim - When is there going to be a release?
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 20th Mar 2014 02:04
I think the AppGameKit compiler does not make the labels (lines ending with ":") scoped for the functions they are in.

It probably replaces all references to the first occurance of a label when building the byte code.

Try different labels. Or, better yet, don't use Goto.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Mar 2014 02:07
I can't think of anything worse than using goto inside a function, especially like that. Learn to exit to escape from loops or exitfunction to quit the function entirely.

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 20th Mar 2014 08:35
the AppGameKit compiler is not the best,
should say label already used or do what u want.
means in visual basic i can use also the same label name inside
each function. we often use for error handling.

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
Chmava
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location:
Posted: 24th Mar 2014 13:29
The problem is much simpler, like a function name, it has to be *UNIQUE*.

"goto" & "gosub" can indeed go out of function it seem.

Just use "goto skip1" &/or "goto skip2" instead, hopefully you calculated the consequences of using goto, which as many before has stated, can indeed bug up real bad.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Mar 2014 20:47
Quote: "The problem is much simpler, like a function name, it has to be *UNIQUE*."

Oh how I wish for overloading!

Quote: ""goto" & "gosub" can indeed go out of function it seem."

That just sounds like such a bad idea!

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Mar 2014 22:03
Quote: ""goto" & "gosub" can indeed go out of function it seem."


Nooooooooooooooooooooooooooo!
That (Goto) will cause a stack overflow and kill your program stone dead. I don't usually get involved with the "Goto is bad" debate, but this is exactly why GOTO - when used without the knowledge of what it does - should not be used.

SamKM
14
Years of Service
User Offline
Joined: 25th May 2009
Location:
Posted: 25th Mar 2014 01:23 Edited at: 25th Mar 2014 01:24
GOTO IS EVIL
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 26th Mar 2014 02:06 Edited at: 26th Mar 2014 02:08
nice cartoon! lol

why not combine your settings into a single function...



Login to post a reply

Server time is: 2024-05-05 04:08:57
Your offset time is: 2024-05-05 04:08:57