Reading information

Blitz3D Forums/Blitz3D Beginners Area/Reading information

Yahfree(Posted 2007) [#1]
Hey, my current project requires me when called to know information about something

i want to have the user to be able to select something from the drop down menu then press next, after this it, it knows what the user pressed and displays the info about this, and uses the info ect..

lets say i want to know how many doors a car has..

the user selects the car from the drop down menu, press' next and it reads the info about that car off of a .txt file or somthing.. from there i can use this info any way i want


how do i do this? is it possible to look for keywords on a .txt file then read them?

like the .txt file is:

Car1
----
2 Doors
1 Engine

Car2
----
4 Doors
1 Engine



how could i Search for say "Car2" then read off whats under it?

or is there a simpler way to do this? and not create a million veriables for each car in the program by hand?

i'd rather read off somthing

if not, is there a simple way to do it with types or somthing?

basicly when i need the info i want to be able to pull it up, this can be achived alot of ways, but i want to find the easyest way before i atempt to do this cause i'm talking 20-70 different 'Cars'.


Yahfree(Posted 2007) [#2]
Ok i think i may go with types, can one of you tell me how to get a veriable to hold info for a type? err like this example:

Graphics 300,500,16,2

Type car
Field doors
Field engines
End Type

car1.car = New car
car1\doors=4
car1\engines=1

;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
PickedCar$="car1";!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
While Not KeyHit(1)
Cls

Text 0,0,"car1 has: "+PickedCar\doors+" doors"
Text 0,20,"car1 has: "+PickedCar\engine+" engine(s)"

 
Delay 5
Flip
Wend
End


Is there a way to get something like this to work? because that doesnt work ... :\



Edit: Remember this is my first project involving types.. i have no clue what i'm doing, making it up as i go


Trader3564(Posted 2007) [#3]
Okey,

first you need to understand what a "TYPE" is.
A type is a "custom object" with "custom properties".

Example:
Type myObject
    Field Name
    Field Shoes
    Field Hat
    Field Pants
    Field TShirt
End Type


The advantage of an object is that you can create more then 1 instance of the same "thing".

So i go like

john.myObject = new myObject
peter.myObject = new myObject
marry.myObject = new myObject


Then i can set the properties anytime, anywhere in the game:

john\name="john"
john\pants="blue jeans"
peter\name="peter"
peter\hat="yankees cap"
marry\name="marry"
marry\shoes="brown highheels"


you may also add a bunch of random dudes:

for i=1 to 10
     randomdude.myObject=new myObject
     randomdude\name="dude"+i
     randomdude\TShirt="orange small"
     randomdude\Hat="blue cap"
next


Now you got 10 orange small dudes added.
Ok, so how do we select one of these dudes later on? because we did not name them individualy like we did with john\, peter\ and marry\. After all, they are all called "randomdude\" and overwrite that variable as we create a 2nd dude, and 3th, etc...
That is why i added the field "Name" so we can still simply store their unique names (or ID, whatever you want) without having to copy and past the "create randomdude code" 10 times, as we had to do for john\, peter\ and marry\.

That would work like this:

Function GetDudeByName(name$){
for dude.myObject = each  myObject
     if dude\name=name$ then return dude
next

mydude=GetDudeByName("dude1")
Text 10,10,"Dude1 has a "+mydude\TShirt+" tshirt."
Text 10,30,"Dude1 has a "+mydude\Hat


I hope this helps. I doubt there is anything else i can do if not.


b32(Posted 2007) [#4]
Also, to read a textfile (or Data in this case), you could strip it down using Mid$() and Instr():



Yahfree(Posted 2007) [#5]
Thanks guys,

But what i'm saying is:

How do you store a name in a veriable ,(PickedCar$="car1")

then check that agenst a type?

like the user Cicks a button that makes:(Pickedcar$="car2")

i want to use this 'Pickedcar' as the type name, so it can change

like so:

text 50,50,Pickedcar$\doors

but that doesnt work? how do i get it to work? i get "Veriable Must be a type" error? well it is a type, its just masked under a veriable that can change?


is this posible?

in this little example, theres 2 objects "car1" , and "car2"

This would work:

text 50,50,car1\doors
;---

this would not:

Pickedcar$="car1"
text 50,50,Pickedcar$\doors
;--


Why?????


b32(Posted 2007) [#6]
You could add a 'name$' field and loop through the cars to search for the car with the right name:
For c.car = each car
 if c\name$ = "Car2" then
   print c\doors
 end if
next

Else, you could use a Dim to store the type instances:
Dim indexedcar.car(10)
indexedcar(0) = new car
indexedcar(1) = new car
etc.

Then you could strip the index number from the string and retreive the right 'indexedcar' with it.
index = mid$(pickedcar$, 4)
indexedcar(index)\doors



Trader3564(Posted 2007) [#7]
i don't see whats wrong with my example or that of b32.
Yahfree, what is your progamming experiance?
there is in any language sush a basic thing as

types/object
variables
contants
functions
math

and if you do not first learn how that works, or what it is, its very hard to acomplish anything with programming. i get the impression you do not know what a type or object is, and how to use it.
as your are using a string variable as an object.


Gabriel(Posted 2007) [#8]
Blitz doesn't have runtime reflection, so it does not know what you've called the variables. Indeed, they don't have the same name when the game is compiled. If you must refer to things by name you are going to need a name field. I would also suggest a more efficient data structure than a linked list for storing them if you're going to access them by name.


Yahfree(Posted 2007) [#9]
Experince, i'm still a newb, (blitz is my first programming language) i know most of the stuff, but this is the first time i'v used types..

@ b23

i'm liking the first example, i'll mess with it when i get the chance, thanks for the help


Yahfree(Posted 2007) [#10]
Works perfectly B23, just what i needed, Thank you


Trader3564(Posted 2007) [#11]
ah, okey... well use what suits you best :) im glad we could help.


Yahfree(Posted 2007) [#12]
Yeah this should do fine, i'll let you know if i run into any brick walls so far so good!

again thanks


Yahfree(Posted 2007) [#13]
Does anyone by chance know any methods of finding out if a letter in a string is uppercase/lowercase and how to change that letter to uppercase/lowercase?

i know how to find the letter (use the Right() or Left() commands) but i don't know how to find out if its uppercase or lowercase

Thanks


b32(Posted 2007) [#14]
Use Lower$(), Upper$() to change case.
And to determine if a character is uppercase, use:
If (c$ = upper$(c$)) then print "uppercase!"


Yahfree(Posted 2007) [#15]
Thanks


Yahfree(Posted 2007) [#16]
Edit: after messing with it for a hour or so i finaly got it to work, thanks anyways


Yahfree(Posted 2007) [#17]
Ohh, well heres a question: how do i add percentages subtract ect?

i wish i could do this atm:

number=number+5%

but as far as i know, % is the sign for a int.


b32(Posted 2007) [#18]
Maybe like this ?
number = number * 1.05 ?


Yahfree(Posted 2007) [#19]
Hmm, how do i take a type field (like your example above that i'm messing with right now) and see if it doesnt match up with anything?

like if the user types in "blahblah" for example, and theres no cars by the name "blahblah" how would i check ?


b32(Posted 2007) [#20]
You could use a 'flag' variable that indicates if a valid car has been found. So, before the For..Next loop, make a variable 'found' and set it to zero.
If you found a car with the specified name, change it to one, and optionally, leave the loop using 'Exit'
Then, say: "if found then .. etc", so that you only respond if a car has been found.


Yahfree(Posted 2007) [#21]
Thanks b23, i'm starting to really like these types, and <Que Scarey sound> Understand them.

dang i wish i learned these things earlyer, they woulda helped ALOT on a few projects i'm working on


Yahfree(Posted 2007) [#22]
Whats wrong with this? it flashs them on, then they are gone on the next frame?


why doesnt this work?
For i=1 To 8
Oval hsx,200,15,15,1
hsx=hsx+16
Next


but in the same place in the code this does?

Oval hsx,200,15,15,1


??


b32(Posted 2007) [#23]
Instead of increasing hsx, you could better try this:
For i=0 To 7
Oval hsx+(i*16),200,15,15,1
Next



Yahfree(Posted 2007) [#24]
I feel stupid :\