Results 1 to 10 of 10

Thread: Load/Unload Object PROBLEM

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    12

    Load/Unload Object PROBLEM

    Hi everyone,

    I need help figuring out a way around the Load Object function in my coding. So basically I am making a tetris game where I will load in 4 image boxes at a time. However, after clearing a line, I make these image boxes invisible and place them at .top = 0 and .left = 0 so that they are no longer on the grid. However, after loading many image boxes, the program becomes very laggy and interferes with the game.

    So therefore I decided to use the Unload function, but then I get an error in aspects where it will tell me it cannot carry out a procedure because that object is now missing even though I no longer need it. For example:

    For IndexNumber = 0 to IndNum

    Is there any way around this?

  2. #2
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Load/Unload Object PROBLEM

    if object is never loaded then you cannot unload at the beginning of your sub/function

    vb Code:
    1. On Error Resume Next
    if object is not loaded it will skip

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    12

    Re: Load/Unload Object PROBLEM

    I just tried the On Error Resume Next but it didn't quite work out. Am I placing it in the wrong place? I have it directly underneath For IndexNumber = 1 to IndNum.

    Thanks

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    12

    Re: Load/Unload Object PROBLEM

    I think it's also messing up my variables.

  5. #5
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: Load/Unload Object PROBLEM

    You should be trying to re-use the images rather than constantly adding new ones. You should never create more than can fit on the screen at any one time during a game.

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Load/Unload Object PROBLEM

    1) On Error Resume Next doesn't fix the problem it only hides it. So that's not the solution.
    2) Since you didn't specify what the error is, or what your code looks like, there's nothing more that we can do to help.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    12

    Re: Load/Unload Object PROBLEM

    Quote Originally Posted by ColinE66 View Post
    You should be trying to re-use the images rather than constantly adding new ones. You should never create more than can fit on the screen at any one time during a game.
    That's the problem with tetris. Say the grid has a maximum of 100 spaces. If I do something like this:
    If IndNum > 100 Then IndNum = 0

    then it still holds the potential that Image1(0) may still be on the grid even after Image1(100) has been placed as I may have cleared all the other image boxes, but Image1(0) has still been left over, and this will cause problems as it will just disappear without it being cleared. That is why the safest coding is to load more in for every piece.

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    12

    Re: Load/Unload Object PROBLEM

    Quote Originally Posted by techgnome View Post
    1) On Error Resume Next doesn't fix the problem it only hides it. So that's not the solution.
    2) Since you didn't specify what the error is, or what your code looks like, there's nothing more that we can do to help.

    -tg
    This is basically what's happening:
    Code:
    For IndexNumber = 0 to IndNum 'IndNum being the index number of the final loaded imagebox
    If Image1(IndexNumber).top = 8000 then Unload Image1(IndexNumber) ' to clear the line
    Image1(IndexNumber).top = Image1(Index).top + 375 'to move all blocks down 1 line
    Next
    Basically the error I am getting once Image1(IndexNumber) is unloaded, then the "For" process cannot keep going as there will be a missing object. Is there a way where it can skip that index number if that object does not exist?

  9. #9
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: Load/Unload Object PROBLEM

    Quote Originally Posted by AndroidMachine View Post
    That's the problem with tetris. Say the grid has a maximum of 100 spaces. If I do something like this:
    If IndNum > 100 Then IndNum = 0

    then it still holds the potential that Image1(0) may still be on the grid even after Image1(100) has been placed as I may have cleared all the other image boxes, but Image1(0) has still been left over, and this will cause problems as it will just disappear without it being cleared. That is why the safest coding is to load more in for every piece.
    Well, you have to be smart about how you re-use the images, of course. You can't simply roll-over the number for the reason you mention. I would create a Data Type similar to the following:

    Code:
    Dim BlocksPerLevel as Integer
    
    BlocksPerLevel= 500 'or whatever
    
    Private Type Block
        ImageIndex as Integer
        BlockCleared as Boolean
        BlockXPosition as integer
        BlockYPositon a Integer
    End Type
    
    Dim GameBlocks(BlocksPerLevel) as Block
    Something like that. Then, once a block is cleared, re-assign a used Image Index to a new GameBlock. Haven't thought the whole thing through - just air-coding but you may get the idea.

    Anyway, don't wish to hijack the thread but my point is that performance in your game will be constant since you will always use the same number of images, i.e. the max that can fit on the game board. This is, of course, provided that performance is acceptable at that number.

  10. #10
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Load/Unload Object PROBLEM

    For IndexNumber = 0 to IndNum 'IndNum being the index number of the final loaded imagebox
    If Image1(IndexNumber).top = 8000 then Image1(IndexNumber).Picture = LoadPicture (""): Image1(IndexNumber).visible = False ' to clear the line
    Image1(IndexNumber).top = Image1(Index).top + 375 'to move all blocks down 1 line
    Next

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width