Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why does this not work? 1

Status
Not open for further replies.

qbasicking

Programmer
Aug 19, 2001
628
US
This code below is for switching weapons in a first person shooter game, it works perfectly...once, then it won't switch again.
I have run check after check on this code, but I can't figure out the problem.

PRINT kbmatrix%(29), special%
IF kbmatrix%(29) AND special% THEN
PRINT "It works!"
a% = spriteph%(special2%)
sprites%(special2%) = weapon%
spritex(special2%) = px
spritey(special2%) = py
spriteph%(special2%) = shots%
weapon% = special%
shots% = a%
END IF


This is the output I get:
---------------------------------
|1 6 |
| |
| |
| |
| |
| |
| |
| |
---------------------------------

Since kbmatrix%(26) = 1 and special% = 6 it should also print "It works!", but I doesn't this seems to contredict basic boolean algebra, could someone tell me whats going on and how to fix it?

FYI:
special% is the type of weapon you are switching to
special2% is the number for the sprite
 
i need more.

basically, when you have,

if kbmatrix%(29) and special% then

either:

if kbmatrix%(29) is not zero and special is not zero then go on:

or:

if kbmatrix%(29) and special% then...

say, you're using a multikey routine, aren't you? ;) does it stick?

because and is a boolean operator, you may be ANDing kbmatrix%(29) by special%. Check out the qb help for more details: i need to brush up on my boolean.
 
even so Barok, if you AND a 1 with a 1 don't you still get a 1?

I'm not all too familiar with the whole boolean thing with QB. why can't you just say &quot;>0&quot; or &quot;<>0&quot; and see if it works then? Isn't it the same as what you are wanting to do?

~PlystirE~
 
What I don't understand is that it works one time, but never there-after.

I'm not ANDing bits, unless it does that by default, I changed nothing.


This is a simple boolean table:
special% kbmatrix%(29) special% AND kbmatrix%(29)
T T T
T F F
F T F
F F F

The first one I'm not getting, I know by printing special% and kbmatrix%(29) are both TRUE, therefore special% AND kbmatrix%(29) should also be TRUE, but its not going on to the next step.


I will try comparing against zero, but I don't think that that will make a difference.


Yes, I am using a multi-key routine, and no, it doesn't stick at all, mine works perfectly.
 
Ok, comparing against zero worked. Now that I've got the problem fixed i would like to know why it worked.

Does qbasic do boolean algebra differently that I thought? I thought that zero is FALSE and any real number is a TRUE, but I've done some work and I found that isn't the case, why is that?
It seems to be that one is TRUE and any other real number is FALSE.
 
ok qbasicking

Quick lesson in ANDing.

1 AND 1 = 1
1 AND 0 = 0
0 AND 0 = 0

6 <> 101 : 6 = 011 (Going from left to right)
1 = 100 (Obviously)

Now, 011 AND 100:
011
100
---
000

Therefore, the ending result is FALSE and will not run through your If Then block.

Hope that made sense ;)

GL
~PlystirE~
 
thanks too. i myself want to learn more about boolean operators. i've found out lots using them in if...then satatments for logic operators, but not for determining variables. the only one i understand well is not, which of course returns the negative of a variable. maybe a bigger lesson on the boolean operators? thanks.
 
haven't taken it yet. i'm taking math30a as we speak. i'm trying to teach myself calculus from a book, but it's going very slowly.
 
Oh, it would be really slow trying to learn it yourself.
 
well I took AP Calculus, but we never covered boolean operations. I learned this from using the C64 and from taking Cisco class :)

~PlystirE~
 
A bit off course, but...

Plystire,
Is there a reason you writing the bits left to right?

Were you numbering...
Code:
0 = 000
1 = 100
2 = 010
3 = 110
4 = 001

Instead of the usual notation:
Code:
0 = 000
1 = 001
2 = 010
3 = 011
4 = 100

I am used to seeing the Second such as if it the were decimal or hex:
Code:
  9
+ 1
---
 10
(decimal: base 10)

Code:
  F
+ 1
---
 10
(hexadecimal: base 16)

Code:
  01
+ 01
----
  10
(binary: base 2)

You had me confused there for a minute when 6 = 011 instead of 110... ;-)

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top