Results 1 to 3 of 3

Thread: Problem with integer

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2022

    Problem with integer

    I did:
    HTML Code:
    Dim doorkeys As Integer = 3
    And I want to do that every time "player" touches a key out of "key1, key2, key3", Then the number of doorkeys minuses by 1
    For example:
    HTML Code:
            If player.Bounds.IntersectsWith(key1.Bounds) Then
                doorkeys = doorkeys - 1
    But the problem is that the number of doorkeys minuses by 1 every millisecond the player is in touch with key1
    How do I fix that?
    (The keys are pictureboxes and the player is picturebox)

  2. #2
    Join Date
    Nov 2017

    Re: Problem with integer

    We're obviously not getting the whole picture of what your code is doing if that code is running every millisecond. Presumably, you have some timer that is running that is doing this Intersection checking, and each time the timer ticks it is decrementing doorkeys.

    If the Intersection condition is True, you will need to do something to indicate that this intersection has already been handled so that subsequent checks of this condition no longer evaluate as true (unless some other condition has take place in the meantime that make this evaluation being true potentially relevant again).

    That being said, I can't suggest a good way to do this based solely on the minuscule amount of code provided, and limited context described of said code. It could be a boolean, it could be "moving" the player so that the Intersection is no longer true, it could be one of a number of other options.

    Good luck.

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002

    Re: Problem with integer

    I was thinking along the line of usibng the .Tag property ... set it to True or "Available" initially ... then in the if statement, also check the .Tag. If it's True or "Available" then you set it False, or "" (or "Unavailable", or "Used" ... or anything other than what the default was) and decrement the doorKeys count.
    When it comes back in to the loop, the .Tag will have changes, so it will not decrement the counter.

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

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