
-----------------------------------
Archi
Sun Jul 20, 2003 6:53 pm

Checking An Array For Validity
-----------------------------------
How would I go about checking to see if every part of an array is either valid or invalid. I'm going ot use this for my workshop type system for my game. And if every part of the array is " " or has nothing in it, then i don't want to give the user the option to use that part of the workshop. But if it does have something in it, then i'd like for that part to be shown.

-----------------------------------
AsianSensation
Sun Jul 20, 2003 6:59 pm


-----------------------------------
as far as I know, you cannot check to see if a variable contains a value or not.

var a: int
var ans: string
get ans
if ans = "y" then
   a+=1
end if


this simple piece of code gives a value to a if "y" is inputted as an answer. However, if something else is inputted, a will not be assigned a value.
In turing, you cannot check to see if a variable contains value or not.

also, what do you mean by valid? Could you specify that?

The best bet is to assign every element of the array a value, such as a blank, and when you compare value, if it's a blank, then you know it's invalid, again, I need a specific definition for valid.

-----------------------------------
Archi
Sun Jul 20, 2003 7:29 pm


-----------------------------------
Well in the workshop, they combine 2 items together and if they have any gems they will also appear so that they can choose to use them... But if they don't have any, I don't want the array which would hold the gems in to appear.

So either the array would hold a gem name or just a " "

-----------------------------------
Dan
Sun Jul 20, 2003 8:28 pm


-----------------------------------
i there are two ways i whould do this:

1. use two arrays, one with on or " " and one with what the room is


var test : array 1 .. 5 of string
var partName: array 1..5 of string

partName(1) := "Main room"
partName(2) := "Computer room"
partName(3) := "Hacking room"
partName(4) := "Dan's room"
partName(5) := "Tony's room"

test(1) := "on"
test(2) := "on"
test(3) := " "
test(4) := " "
test(5) := "on"

put "open rooms: "

for i : 1 .. 5
    if test(i) not= " " then
        put partName(i)
    end if
end for


the othere way i whould use is to just use one with everything in it:


var partName: array 1..5 of string

partName(1) := "Main room"
partName(2) := "Computer room"
partName(3) := " "
partName(4) := " "
partName(5) := "Tony's room"

put "open rooms: "

for i : 1 .. 5
    if partName(i) not= " " then
        put partName(i)
    end if
end for


-----------------------------------
krishon
Mon Jul 21, 2003 9:02 am


-----------------------------------
lol, Dan told u asian

-----------------------------------
AsianSensation
Mon Jul 21, 2003 4:44 pm


-----------------------------------
lol, Dan told u asian

huh? what? Dan told me how?

-----------------------------------
SilverSprite
Mon Jul 21, 2003 5:25 pm


-----------------------------------
Dont act all innocent Asian.. hahahahaah

-----------------------------------
PaddyLong
Tue Jul 22, 2003 3:08 am


-----------------------------------
a boolean fucntion for this would be good


function validArray (checkThis : array 1 .. * of string) : boolean
    for q : 1 .. upper (checkThis)
        if checkThis (q) = " " then
            result false
        end if
    end for
    result true
end validArray

