Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problems with if, and, or
#1
First off, I want to say hello everyone. I just found out about freebasic a couple days ago and I'm very excited about it. I used to program in QB all the time a few years ago. Well I havn't touched it for a couple years and now I want to get into it again. I've decided to write a simple tic tac toe game to get back into the groove but I'm having some problems. First off, I have my board array set up like so ..
Code:
dim shared board(0 to 2,0 to 2) as integer

Here is a trimmed down version of what's causing my problem.

Code:
function checkwin
   if board(0,2) = 1 and board(1,1) = 1 and board(2,0) = 1 or
      board(0,0) = 1 and board(1,1) = 1 and board(2,2) = 1 then    
      checkwin = 1
   else
      checkwin = 0
   end if
end function

If I try to compile that I get an error 9 : Expected Expression
if board(0,2) = 1 and board(1,1) = 1 and board(2,0) = 1 or

If I replace that or with a then and comment out the other board checking lines it compiles just fine. That leads me to beleive that I'm using 'or' wrong. All I have for reference are some old QB tutorials I've found and from what I can tell it should be correct .. can anyone help me out?

Thanks,
Gunder
gunder
"I have a perfect body, but it's in the trunk and starting to smell."
Reply
#2
To break lines use the underscore character (_) at end of each line, that's the QB/VB/PB way to do line-continuation, ie:

Code:
if board(0,2) = 1 and board(1,1) = 1 and board(2,0) = 1 or _
      board(0,0) = 1 and board(1,1) = 1 and board(2,2) = 1 then[/code]
Reply
#3
Thank you, that fixed it, I completely forgot about using the _ to break up lines. Now I have one other dumb question. I first was trying to set up the board array as 1 character strings like so ..

Code:
dim shared board$(0 to 2,0 to 2) as string * 1

That wouldn't work, I can't remember the error off the top of my head and I'm at work so I can't check it. From the tutorials I have I would think that would give me a 3x3 array of one character each. Am I making another idiot mistake?

-gunder
gunder
"I have a perfect body, but it's in the trunk and starting to smell."
Reply
#4
Code:
dim shared board(0 to 2,0 to 2) as string * 1
You can't use both the $ typedef character and As String, even in QB.
Reply
#5
also you should use

Code:
dim shared board(0 to 2,0 to 2) as byte

it just be easyer to code that way.
Reply
#6
Quote:
Code:
dim shared board(0 to 2,0 to 2) as string * 1
You can't use both the $ typedef character and As String, even in QB.

Hrm, I'm a lot rustier than I thought I was. I thought that the $, % and so on were just symbols to help define what they were. So would it be better to use

Code:
dim shared board$(0 to 2, 0 to 2)

or

Code:
dim shared board(0 to 2, 0 to 2) as string * 1


Quote:also you should use
Code:
dim shared board(0 to 2,0 to 2) as byte
it just easyer to code that way.

Ok, I'll look into the differences between integer and byte when I get home. Thanks for the tip!

-gunder
gunder
"I have a perfect body, but it's in the trunk and starting to smell."
Reply
#7
Definitely use:
Code:
dim shared board(0 to 2, 0 to 2) as string * 1
The type suffixes are just supported for backward compatability.

Byte is 1 byte (8 bits) long, whereas Integer (on 32-bit x86 processors, at least Smile ) is 4 bytes (32 bits) long, meaning that you can store larger numbers in Integer variables than in Byte variables. Since you used "As String *1" in the original code, you probably only need a Byte variable, but since modern processors operate on 4-byte data faster than 1- or 2-byte data (and because of the need for conversions to 4-byte from 1-byte, which are rather fast, but not to be totally ignored), I would stick with Integer.
Reply
#8
Thank you DrV! That explained a lot. Hopefully I can finish my little game now withought any more newbie questions. Thanks for your quick replys everyone, your great!

-gunder
gunder
"I have a perfect body, but it's in the trunk and starting to smell."
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)