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 / Problem with global arrays in functions - please help

Author
Message
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 14th Jan 2015 10:06
Hi all,

hoping someone can help, I am new to AGK2 but have done some projects a while back in DarkBasic Pro so not fully new to programming.
I am having some trouble with the code below regarding arrays.
This is the start of a flood fill routine which takes the image, PIC4.png a 640 x 430 image with white as the background colour and black as a line drawing for areas to colour in and then uses a 2D array of the same dimensions to store a set of numbers from 1 to ? depending on the complexity of the drawing.
The array stores a value at the pixel co-ord for x and y and is reference to a fill area. So what it does is give a fill area a specific number a bit like paint by numbers but each fill area on the screen has it's own number area.
I haven't got to the part where I actually paint yet but just doing the storing of the numbers so far.

If I run the program with the Print commands un-commented in the function storeFillPixels then the correct values are shown in the array pixelStore[x,y], however if I re-comment the Print commands back out to then see the pixelStore[x,y] values printed in the main program it shows some odd values store eg 37 and 256 instead of starting at 1.

Any ideas or if this makes sense?
I am storing the values this way instead of doing a tradition fill to obtain the different values for each fill area on my pic as the program I am creating is going to be a colouring book style program but with not the normal flood fill for colouring the areas.

Thanks in advance.



Background:
AMOS on the AMIGA!

Attachments

Login to view attachments
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 14th Jan 2015 18:50
Just been having another look but no matter what I do it doesn't seem to sort the problem.
For some reason after creating the array inside the function and checking it is fine, it doesn't seem to print correctly outside the function.

Getting frustrated now because I want to move on to the next part of the program.

Background:
AMOS on the AMIGA!
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 14th Jan 2015 19:44
Okay another quick update.
To test this theory I changed the function call to a gosub routine, I know I hate gosub commands also but it needed to be tested to see if this was something to do with the function.

Result, well I was shocked that it did the same thing.
Is this something to do with Arrays or is it my code.

Can someone please try it on there computer, using windows to see if this does the same or have a quick look at the code to see if it is something really stupid I have done!?!?!?

By the way forgot to mention that the picture is saved in this post too to test on.

Thanks

Background:
AMOS on the AMIGA!
Yodaman Jer
User Banned
Posted: 14th Jan 2015 19:51
I can't seem to get it to run, it compiles just fine but as soon as it launches I'm met with a "application.exe has stopped working" error message and I have to force quit it.

Your global arrays look fine as far as I can tell, what have you tried exactly?


It's back, baby!
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 14th Jan 2015 20:18
Hi, Yodaman.

I've been doing some more messing with this but first did you save the pic in a media folder from the download button? It is a 2D dog black and white pick attached to the first post. Just wondering if thats why it crashed?

Anyway I have just found that through the routine it works fine storing 1 in the pixelStore [ 1, 1 ] until it gets in the cycle for rows=10 and columns=25 then for some reason pixelStore [ 1, 1 ] shows to be 18 and this value goes up as it goes through the routine!

Going to check the for and if places and variables etc but strange it adds 17 to the pixelStore [ 1, 1 ] when it gets to the mentioned rows and columns in the for next part.

I am baffled!


Background:
AMOS on the AMIGA!
Yodaman Jer
User Banned
Posted: 14th Jan 2015 20:25
D'oh, I forgot to move the downloaded pic to the media folder.

All I see are the numbers on the side increasing and nothing else. The numbers are climbing really far up really fast, too. I am also baffled as to why this isn't working.

Maybe another well-seasoned user will see this and help out as well?


It's back, baby!
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 14th Jan 2015 20:38
I must have done something strange because when checking that dog picture pixelStore [ 1, 1 ] changes at a couple of points from the number 1 stored that it should be.

As mentions changes to 18 at rows=10 / columns=25 then changes to 37 at rows=264 / columns=15

Hmmmm

Background:
AMOS on the AMIGA!
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 14th Jan 2015 21:16
Well, everyone just ignore this post because I have just realised I have been a complete idiot!

The program does exactly what it should do!!

When I wrote the routine I tested it on a small picture of just a couple of circles on graph paper going through the routine section by section and pixelStore [ 1, 1 ] stayed the same, however on a more complex picture the fill number may change at the end of the routine.

As it test's one pixel at a time the routine checks the pixel above and the pixel to the left. If these are both black pixels it creates a new fill number thinking it has come across a new fill section but this then gets changed later during the stack for/next section so the fill section has the same value if the previous number found is not enclosed!

What an idiot I feel wasting a full day on a routine that works

So there you go haha

Maybe this routine might come in handy for someone so I might do a tutorial on it when finished

Happy coding and thanks for looking Yodaman.

Background:
AMOS on the AMIGA!
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 14th Jan 2015 21:23
Have a look at the code to see a section fill in red.

The final routine won't colour the section using the DrawBox command but I just wanted to do a quick test to see if the concept works!

I will comment the code and upload as a tutorial soon and hopefully someone will find it useful.

Thanks for now



Background:
AMOS on the AMIGA!

Attachments

Login to view attachments
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 15th Jan 2015 05:10
Quote: "What an idiot I feel wasting a full day on a routine that works"

This happens to even the very best programmers.

The good thing is when you finally realize tht your mistake is that there is no mistake. Forehead smacking, swearing and walking away from the computer in disgust is the usual response.

Cheers,
Ancient Lady
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 15th Jan 2015 12:31
Yep that was exactly the response but it works so onto the next step

Background:
AMOS on the AMIGA!

Login to post a reply

Server time is: 2024-05-05 22:18:56
Your offset time is: 2024-05-05 22:18:56