Results 1 to 5 of 5

Thread: [RESOLVED] MonoGame Images Not Added To List From For Loop

  1. #1

    Thread Starter
    Member Cow124's Avatar
    Join Date
    Aug 2014
    Posts
    36

    Resolved [RESOLVED] MonoGame Images Not Added To List From For Loop

    The problem I am having is that when I am using the Load Sub, the For Loop does not add images to the list, as seen by the Message Box of the Count Property of the List(bswimages)(Returns 0). How do I fix my code in order to have the images put in the list. Thanks in advance.
    Code:
    Private bswimages As New List(Of Texture2D)()
    Protected Overrides Sub LoadContent()
                    ' Create a new SpriteBatch, which can be used to draw textures.
                    spriteBatch = New SpriteBatch(GraphicsDevice)
                    ' TODO: use this.Content to load your game content here
                    'Load BShooterWalk Animation Content (pngs)
                    Dim bswimages As New List(Of Texture2D)()
                    Dim bswfolderPath As String = "Images/BShooterWalk/"
                    For i As Integer = 0 To 33
                        Try
                            If i <= 9 Then
                                bswimages.Add(Content.Load(Of Texture2D)(bswfolderPath & "bshooter_" & "00" & i & Convert.ToString(i.ToString)))
                            Else
                                bswimages.Add(Content.Load(Of Texture2D)(bswfolderPath & "bshooter_" & "0" & i & Convert.ToString(i.ToString)))
                            End If
                        Catch
                            Exit Try
                        End Try
                    Next
                    MsgBox(bswimages.Count)
                End Sub

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: MonoGame Images Not Added To List From For Loop

    It's because you defined two variables with the same name... one outside the sub (presumably at the class level) and one INSIDE the sub... so when you then reference your list, it thinks you want the one inside the sub... so it loads the images into it... but when the sub then exits, the variable goes with it, leaving you with your empty, class level one.

    So the solution is simple... remove the bswimages declaration in the sub.

    -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??? *

  3. #3

    Thread Starter
    Member Cow124's Avatar
    Join Date
    Aug 2014
    Posts
    36

    Re: MonoGame Images Not Added To List From For Loop

    Even with the bswimages declaration in the sub removed, the msgBox gives me a value of 0.

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: MonoGame Images Not Added To List From For Loop

    THen there's an error happening... but your catch doesn't deal with errors, it simply exits. That's the equivalent to an On Error Resume Next... Take out the TRy Catch and see if you get any errors.


    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??? *

  5. #5

    Thread Starter
    Member Cow124's Avatar
    Join Date
    Aug 2014
    Posts
    36

    Re: MonoGame Images Not Added To List From For Loop

    Thank you! My problem was solved.

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