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 / First major error...

Author
Message
David Gervais
Retired Moderator
19
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 13th Feb 2014 16:07 Edited at: 13th Feb 2014 16:10
Hello all,

I ran into my first ever game crashing error... game froze up when all it was asked to do was PlaySound(Buzzer)

this was the error..



not sure what it means, but in my code where this error happened the code looked like this..



After looking at the code for awhile I decided to try a little change..

below the do-loop I changed this line and added a Sync() between the loop and if statement..



My question is.. could this line..

if magover > 0 and magover < 8

have caused the error? and was it because I already did a check of magover > 0 On the line where it checks the mouseclick condition in the do-loop prior to this?

I seem to have fixed the problem, but I'd like to know if this was indeed the error?

Cheers!

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th Feb 2014 16:55
at the first code example i would say you call PlaySound often in a loop.
what value is (mn)?
maybe try GetSoundsPlaying( iID ) before play again.

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
David Gervais
Retired Moderator
19
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 13th Feb 2014 17:25
Hi Markus,

the mn variable is the number of 'magnets' in this case that you get to place.. it exits the function when the mn reaches zero..

the PlaySound(Buzzer) is only called within the if-elseif statements if the condition is met. I have no Sound statements within the actual loops.

I changed ..



to..



that's the only change I made and I have not been able to get the game to crash like it did before, even when I encounter the same situation in the game.

I suspect the 'AND' statement is not liking the use of the same variable.. all examples I found show this type of entry..

if a=1 and b=2 then c=3

or

if a>1 and b<6 then c=2

nowhere have I found an example where 'a' is used in both conditions like

if a>1 and a<22 then c=17

Anyways, it's a strange bug, and the error code is meaningless to me, so that doesn't help.. and it didn't point to any line number, the program 'stopped' responding and when I told windows to 'close program' that error code was placed in the compiler window in red text.

Seems the bug has been squashed.. so I'll move on and keep going.

Cheers!

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 13th Feb 2014 18:27 Edited at: 13th Feb 2014 18:36
That looks like the error I get when accessing uninitialized variables or arrays - usually due do a typo - which any statement could cause.

If this is the case, it is unlikely to be "if magover < 8" as magover is accessed previously in the do loop. However the following line "if magnetinfo[magover] = 1" looks like the first time magnetinfo[] is accessed in the function.

I would look at the possibility that magover has gone out of the bounds of magnetinfo[] or that the content of magnetinfo[] was not initialized when this function was reached.

edit:
I notice also that if the first block is not used (magover < 8), the alternative (magover > 7) has no upper bounds check.

So what would happen if magover was 350423 for example at this point ?
David Gervais
Retired Moderator
19
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 13th Feb 2014 19:35 Edited at: 13th Feb 2014 19:52
the magnetinfo[] is defined at the start of my code in a setup function..



I have a simple logic function to get which magnet the mouse cursor is hovering over...



No rocket science here.. if the mouse is not over any magnet I set the value to Zero.. magover is also a Global variable.. so as you can see it can never be bigger then 14 and never below Zero.

Basically I have 7 magnets on the left side of the tableau and 7 on the right.. numbered 1-7 and 8-14 respectively. the logic in my magnetize function is to place a magnet if there is not one already, and also check if there is one on the opposite side and if yes, turn off that one and turn on the other.. they act like a toggle.

I'll be posting a WIP soon, just want to knuckle down the 'mechanics/logic' for the gameplay then I'll be ready to start working on the scoring.

I'm not the best programmer, and I know I have allot to learn, and things can always be done differently. I'll be including the source code with my WIP. I'm having fun learning the language and it's fun to see how far I can take my old game designs.. These certainly do qualify as 'Deluxe' versions of my old QBasic 4.5 games.

Target Dice was my first Conversion/Rewrite I think it turned out rather well, even if I only got 2 posts for feedback. LoL.. good thing I'm self motivated

Cheers!

***********************************************************

EDIT: Anyone have DosBox? want to see some of my old games?

https://forumfiles.thegamecreators.com/download/2500859

create a folder (ie:C:\GP) and unzip the gp.zip within this folder.
in DosBox type the following..

mount c c:\GP [enter]
c: [enter]
gpmenu [enter]

this game pack menu will launch the different games, all are fully working, you can even play my original Target Dice and then compare it to the AppGameKit version posted on the showcase boards. Tumble match is the one I'm currently upgrading/converting/rewriting in case you want to give it a look.


Cheers v2.0

fog
21
Years of Service
User Offline
Joined: 5th Oct 2003
Location: Newcastle, England
Posted: 13th Feb 2014 20:36
In your first unmodified version with 'if magover > 0 and magover < 8' it was possible to drop through that function without Sync() ever being called.

Sync does a lot more than just refresh the screen so not calling it could have caused the problem.

Incidentally you really should just have one Sync() in your main loop and not have it dotted around all over. Unless you like debugging hell

And look into using a State Engine. You want to get away from having Do/Loops in your functions as that stops anything else from updating.

eg. if you also had a function that displays your score then it would never be displayed while your code was stuck in that Do/Loop

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 14th Feb 2014 13:01
hmmm,
the changes you had done make not really sense for me.
whatever, any reason the crash will had.
i also suggest, use only one sync in main loop because it refresh the input status etc.

here i think it should be 15 not 14,or AppGameKit do a auto redim.
Global DIM magnetinfo [14] as integer
for pp = 0 TO 14

in the help i see the dim is the number of entrys
dim myValues [ 3 ]
myValues [ 0 ] = 10
myValues [ 1 ] = 20
myValues [ 2 ] = 30

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Feb 2014 17:41
Why so many sync calls?

David Gervais
Retired Moderator
19
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 14th Feb 2014 18:36 Edited at: 14th Feb 2014 18:44
ok, remember I'm a relative noob to this AppGameKit, and programming in general.. a closet programmer at best.. and I put syncs when I find that things like cursor and stuff don't get updated unless there is a sync.. some of these functions keep the code inside them until all the conditions are met, and hence I need to put mouse handling routines 'with sync' within many of my functions..

One of the complaints (or criticism) on Target dice was the the mouse would go inactive (or seem to) while the code was performing different functions.. hence I added redundant mouse checks updates and sync() code all through my program where there are pauses.. If I didn't do this, the mouse movement is jerky and feel odd during play.

yes this is probably not the 'Norm' but I step through my code one step at a time, and that makes me a sequential programmer.. I'm not good enough to design and think in parallel processing. is this wrong? My answer, is Not if it gets the job done. is it pretty? probably not. but people aren't going to spend hours scanning my source code so not very important.. (heck my coding style can bee seen in full view, I included the source code for Target Dice, and in spite of 400+ downloads, no constructive comments, other than the 2 people who suggested gameplay changes.)


And markus, the DIM myval[3] statement has 4 elements, there was a discussion about this in another thread.. I too always thought that Dim myval[3] meant it had 3 elements [0,1,2].. but apparently it has 4 [0,1,2,3]. so you can ignore the '0' if it makes you feel better (which is what I do for the most part).

Anyways, thanks for the feedback.

Cheers!

Edit.. P.S. fog, I looked into a 'State Machine' code thing. my brain imploded,.. that's some serious advanced coding.. I'd almost call you a bully for dropping that suggestion on me ( LOL Just Kidding).. that is way beyond my coding comprehension skills. Also, all the examples I found and discussions were for C++ nothing for that type of code in T1 Basic AGK

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 14th Feb 2014 19:24
in past i had some odd behavior with dim and array bounds.
because that i had mentioned.
The main point is that your problem is gone

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
fog
21
Years of Service
User Offline
Joined: 5th Oct 2003
Location: Newcastle, England
Posted: 15th Feb 2014 01:45
Hi David.

Using a state engine isn't advanced at all and will, if anything, make coding a whole lot easier.

Essentially you just use a Select/Case to divide up your code into logical sections.

A bit of pseudo code to give you an idea of what your main loop would look like:



You can then break the "Game" section down into smaller game related chunks if required.

I might have something like 25k lines of code in my engine, but the main loop, regardless of what game I'm working on, isn't much more complicated than the example above. It's simple, clean, and easy to maintain.

Any questions on anything then feel free to ask here or fire an email my way.

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 15th Feb 2014 05:15 Edited at: 15th Feb 2014 05:26
@David,

If you are just getting started, using a state machine is the best habit to get into, it will keep your program structured and manageable and they are really not that hard.

Compare fogs Pseudo code with the Main file from my current project.

This is not edited for the post, this is the actual file which runs my game. They are almost identical.

And this is about as big as this file will get. Everything else is in include files.

The main game code is in an include "game.agc", which itself has a similar structure, it has its own state machine;

What this means is that the main loop is called every frame without fail, all input and timing is handled by one set of code, no matter what the game is doing. So if there is a problem - I only have to look in one place.

Anything with a prefix "Core" identifies the contents are located in the core include file (at the top), this is file of common functions used by multiple projects - hence it's location is "../~inc/" a folder shared by multiple projects. This handles the screen display, program timing and user input - things that are common to all projects. My Sync() is located in the function Core_LoopEnd() which is called at the end of every loop.

I have an additional function to change the state, because I use a couple of other parameters, the last different state, the time the app has been in this state and a substate step, which is always zero when the state changes;

This is a modular style of programming, which allows code dealing with a particular type of thing to be kept together.

Some might say it's a lot of work, but I prefer to work this way.

Some say, functions calling functions is a waste of processing time, I say Meh!
David Gervais
Retired Moderator
19
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 15th Feb 2014 14:12
Hello once again,

I think my program is pretty structured, and follows the same logic as your sample state engine. I'm just using if-elsif-else instead of your using 'Select case' take a look at my 2 main functions..



As you can see my main loop only has a single 'Sync()' which is how the main loop should always be. in my main loop all I do is keep track of where the mouse pointer is and if it's over a 'button' I highlight that button and set the 'buttonchoice' variable to let my program know which button the cursor is over. if the pointer moves off the button the button highlight turns off..

In the next part of the main loop, I check to see if a mouse button is pressed and send the program to the buttonact () function where it handles the actions needed for each button.

The actions themselves can be as simple as exiting the program, toggling the music on/off or setting the game actions in motion and stepping through them.

Since I tend to code 'Sequentially' I add functions as needed and make sure they work before moving on. Debugging as I go type thing.. it keeps thing simple for me and for the most part I rarely run into bugs that are not related to the current function I am writing. This is the basic method I use for my programming

When I compare your 'State Machine' to my code, the only difference seems to be you like to use Case Select and I use If-Elseif-Else. As with most things in programming there are multiple ways to get the same thing done, which way is the 'Best' way is a matter of personal choice and style.

This peek into my coding process has been brought to you by "Creative Minds Use AGK" ..

Thanks for all your feedback, the bug has been fixed and the code must go on.

Cheers!

SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 20th Feb 2014 02:34 Edited at: 20th Feb 2014 02:50
the only problem with using if statements is you get only 2 possible solutions in the check....



I like the state check much better too as you can have allot more outcomes to your code as mentioned above. but if you just need a simple do this or that then if statements work great.




edit: lol.... I did not know you could stretch out the if statements to keep writing elseif .... I just learned your bad habit...lol Im just kidding... but using case orientated code is for sure cleaner looking and much easier to debug your code.

Ill give you an example...

Qmidi Studio 2 for pc was written with if statements like crazy. On top of this I never used any functions.... on top of that its all in 1 program listing and is a nightmare to debug and fix anything on it.

The best advice I can give you is to place lots of text comments in your code and to use multiple files for your code and functions for easier fixing and adding later on.

I first started using functions and multi code files just on my last 4 projects... I can tell ya it makes things soo much easier to pickup stuff where ya left off even years after you have coded it.

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 20th Feb 2014 02:44
I'm not 100%, but the select should do less comparisons.

For example (comparing like for like);

At each step, the program evaluates what mode equals. So if it's none of the listed options, it has compared it 3 times before the else.

The select should evaluate mode and skip to the case which matches - hence the need for literals in case statements.

Of course the advantages with the if option, is it doesn't need literals and the comparisons don't need to be of the same thing
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 20th Feb 2014 02:56
that's actually a good point marl.

The computer is processing all of your ifs + elseif commands all the time when it could just process the correct case or skip it entirely leaving processing time to be spent else where.

However if its a turn based type of game im guessing your not requiring the full speed of your devices processor.

Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 20th Feb 2014 10:54 Edited at: 20th Feb 2014 10:55
Quote: "The computer is processing all of your ifs + elseif commands all the time "


Wait...I don't think this is true... Take this for example...



Personally, I much prefer the if/elseif approach.
David Gervais
Retired Moderator
19
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 20th Feb 2014 12:07 Edited at: 20th Feb 2014 12:11
as is the case with many languages, the selection of commands like using if/elseif vs select case is a matter of preference.. people will always cite examples of why their choice is 'best'

for example..



knowing how to properly use if/elseif is key. For the most part, EVERY example of the Case Select shows an absolute condition.. in my example wouldn't I need like 100 case = statements?



Correct me if I'm wrong,.. but as I have said.. EVERY example of case select shows this type of structure.. and that would make for thousands more lines of code, and debugging would be a nightmare. in cases where there are only a few choices/outcomes I can see the use of Select Case, but in many cases the if /eslseif works better.

and the if/elseif/else structure is for some reason much easier for me to understand.

my first example could also have been like this..



Anyways, this kind of discussion, often leads to discovering new ways to get the job done. So, it's a good thing.

Cheers!

SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 22nd Feb 2014 02:08
well using an elseif ...this flags that it needs to check it doesn't it?? I would have thought that else ....would be skipped.

but elseif... hum good question. It all depends whats behind The scenes in the AppGameKit engine.... but your probably correct!


secondly does case select need absolutes?? I actually don't know?

@DG your codes perfectly fine! As long as the coder coding it understands it.... that's all that matters.

Out of curiosity what project is this that your working on and for what platform(S) are you targeting?

David Gervais
Retired Moderator
19
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 22nd Feb 2014 03:32 Edited at: 22nd Feb 2014 03:39
This is my second project in AGK.. an old game design by me Called Tumble Match.

http://forum.thegamecreators.com/?m=forum_view&t=210013&b=48

the first game I coded in AppGameKit was Target Dice..

http://forum.thegamecreators.com/?m=forum_view&t=209519&b=48

The download for Target Dice includes the Source Code.. I will also release the source code with Tumble Match when I'm done.

This is part of a remake of an old Game pack I made in Quick Basic 4.5 way back when. I linked the old game pack earlier in this thread, with instructions for using DOS Box to play the old Game Pack.

After Tumble Match I'm going to Remake Stones Throw, a different take on the Yahtzee type game..

Cheers!

P.S. the target Platform for the time being is Windows. but the beauty of AppGameKit is I have Future options available.

Login to post a reply

Server time is: 2024-11-25 02:53:58
Your offset time is: 2024-11-25 02:53:58