none
A problem with code. RRS feed

  • Question

  • Hey guys! How's it going?

    I'm currently having a problem with some code that I'm writing.

    Actually, I suspect it is a problem with small basic, but, I'm not sure.


    -edit-

    Thanks Vijaye!

    The problem lies in my OnMouseDown function, or the graphics window. Whenever I click in the graphics window on one of the buttons which should increment or decrement OffsetX or offsety, it will succesfully do so, and start to redraw the images to compensate for the offset. However, it tends to hit a snag, and stop loading the images, and locks up, I can still type into the console window, and I can loadmap, again, but it's severly broken. It loads the map into random positions, and sometimes tells me there is no map at all, among a host of things.

    But, when I do the same thing by command prompt (Increment/decrement the offsetx or offsety) by input (See: Input 3, 4, 5, or 6) then it succesfully works. Am I just screwing up with my graphics window somehow, or is it broken? Sorry that the code is messy, I don't have the best of habits, but I try to keep some order.

    Ps. This will crash for you without the images. You need to load a map file for some things to work. I will upload my images and map file if you want. And one more question, if I draw an image by GraphicsWindow.DrawImage(Array.GetValue("Tiles",DrawText),x,y) what is the name of the image? Is it C:\documents and settings\...\small basic\map\imagename.bmp"? Or does it not have a name.
    • Edited by Pacolaco Wednesday, December 24, 2008 1:17 AM
    Tuesday, December 23, 2008 10:22 PM

Answers

  • Can you post the resource files that are necessary to run this program?  I'm not sure what to look for without running the program.

    Instead of setting the file names in Array, you could use the ImageList to load them.  You can use numbers as names for the images.

        ImageList.LoadImage(0, Program.Directory + "\void.bmp")
        ImageList.LoadImage(1, Program.Directory + "\grass.bmp")
        ImageList.LoadImage(2, Program.Directory + "\lava.bmp")

    This way when you want to draw an image, you can just say
        
        ' calculate index
        GraphicsWindow.DrawResizedImage(index, j * 25 + 125, i * 25 + 75, 25, 25)

    • Marked as answer by Pacolaco Wednesday, December 24, 2008 1:18 AM
    Tuesday, December 23, 2008 10:49 PM
    Moderator
  • Pacolaco and I spoke offline and we figured the problem was the following:

    There’s an unintended recursion happening in the program.  When you trace the program, this is the sequence of operations (-> means calls)

     

    Start()

    -> TextWindow.Read: This waits for user input

    -> LoadMap2()

                      -> Draw()

                      -> Start()

     

    The problem here is that when the click event fires, the following happens

     

    OnMouseDown()

    -> LoadMap2()

                -> Draw()

                -> Start()

                            -> TextWindow.Read: This waits for user input

     

    Hence when the click happens, the subroutine never returns and hence goes into a deadlock.  The fix is to avoid calling Start() from within LoadMap2().  When I remove the Start() at the end of LoadMap2, your program works great!

    Wednesday, December 24, 2008 1:23 AM
    Moderator

All replies

  • Can you post the resource files that are necessary to run this program?  I'm not sure what to look for without running the program.

    Instead of setting the file names in Array, you could use the ImageList to load them.  You can use numbers as names for the images.

        ImageList.LoadImage(0, Program.Directory + "\void.bmp")
        ImageList.LoadImage(1, Program.Directory + "\grass.bmp")
        ImageList.LoadImage(2, Program.Directory + "\lava.bmp")

    This way when you want to draw an image, you can just say
        
        ' calculate index
        GraphicsWindow.DrawResizedImage(index, j * 25 + 125, i * 25 + 75, 25, 25)

    • Marked as answer by Pacolaco Wednesday, December 24, 2008 1:18 AM
    Tuesday, December 23, 2008 10:49 PM
    Moderator
  • Alright, I rar'ed my whole map folder.

    Download link:
    http://rapidshare.com/files/176228097/Map.rar

    The graphics are.. basic at best haha.

    The most current version of the source I'm using is map3.sb

    The other .sb files are back ups,

    map.txt and map2.txt are test maps that I have been using with various 'curveballs' in them, such as invalid characters, and short lines.

    At the moment I am missing some error catching, and some things are broken (as they should be haha).

    If you load map2.txt, and enter 3 after loading, it should shift the map upwards, loading what was below. You can then enter 4 and return to where you were. There is a little error graphically that I have to fix, but meh. However, if you try to use the down arrow, it offsets, draws, and then functionality ceases.
    Tuesday, December 23, 2008 11:24 PM
  • Hmm... Rapidshare doesn't work from within corpnet here.  Would you mind emailing this to me (a .zip version would be even better) vijayeg atmicrosoftdotcom
    • Marked as answer by Pacolaco Wednesday, December 24, 2008 1:18 AM
    • Unmarked as answer by Vijaye RajiModerator Wednesday, December 24, 2008 1:23 AM
    Tuesday, December 23, 2008 11:35 PM
    Moderator
  • Pacolaco and I spoke offline and we figured the problem was the following:

    There’s an unintended recursion happening in the program.  When you trace the program, this is the sequence of operations (-> means calls)

     

    Start()

    -> TextWindow.Read: This waits for user input

    -> LoadMap2()

                      -> Draw()

                      -> Start()

     

    The problem here is that when the click event fires, the following happens

     

    OnMouseDown()

    -> LoadMap2()

                -> Draw()

                -> Start()

                            -> TextWindow.Read: This waits for user input

     

    Hence when the click happens, the subroutine never returns and hence goes into a deadlock.  The fix is to avoid calling Start() from within LoadMap2().  When I remove the Start() at the end of LoadMap2, your program works great!

    Wednesday, December 24, 2008 1:23 AM
    Moderator