-
Nov 29th, 2022, 12:13 PM
#1
Thread Starter
New Member
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)
-
Nov 29th, 2022, 12:21 PM
#2
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.
-
Nov 29th, 2022, 04:35 PM
#3
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.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|