Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / dbp- loading variable values from a file

Author
Message
BULLSHOCK 2
Retired Moderator
19
Years of Service
User Offline
Joined: 14th Jun 2005
Location: Shocking Bulls
Posted: 26th Jan 2006 18:09
ok

i really need help here. i need a way to load variables from a file.

for example, if i have a file that looks like this:

size=10
weight=25
color=1


how can i load that file into dbpro to define those variables.

ive got it to where i can load it into an array (thanks Xmik) like this:

and it prints fine. but, how do i make those values useful?

i thought i would use a memblock, but im not quite sure how.

UFO
18
Years of Service
User Offline
Joined: 11th Oct 2005
Location:
Posted: 27th Jan 2006 00:38
First, you should save these to the file:
10
25
1
You do not need the variable at the front, and it makes it hard to load.
Then use this code(DBC, but I think this will work in DBP)


Hope it helps


Hippopotomonstrosesquippedaliophobia-Fear of long words
BULLSHOCK 2
Retired Moderator
19
Years of Service
User Offline
Joined: 14th Jun 2005
Location: Shocking Bulls
Posted: 27th Jan 2006 01:05
thats what i wanted to avoid.

my files are editable by the user,
and they arent always in the same order, plus, when my users open the file, i dont want them to see a list of numbers, they need to be able to make sense of the program.

like i have posted abpve, i already have a way to load things into an array, if thats what i wanted to do. but i want my users to define variables, not list numbers.

but thanks for trying to help.

UFO
18
Years of Service
User Offline
Joined: 11th Oct 2005
Location:
Posted: 27th Jan 2006 01:49
You could have it like this:
Size:
10
Weight:
25
Color:
1
and just load the labels into the junk$ variable, or any other variable that has no use.


Hippopotomonstrosesquippedaliophobia-Fear of long words
BULLSHOCK 2
Retired Moderator
19
Years of Service
User Offline
Joined: 14th Jun 2005
Location: Shocking Bulls
Posted: 27th Jan 2006 03:25
but what if they were in a different order than the original file?

the values would all be messed up.

i need a way to compare the variables to hard codded ones, or let the file define all the variables.

i know it seems stubborn, but i need it to be this wy.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Jan 2006 12:15 Edited at: 27th Jan 2006 12:16
UFO's last suggestion is fine. The format is

NAME
VALUE
NAME
VALUE

It doesn't matter if you switch the variables around, as long as they are in pairs.



UFO
18
Years of Service
User Offline
Joined: 11th Oct 2005
Location:
Posted: 28th Jan 2006 00:32
Sorry, but I didn't understand most of what you were asking before, so I can't get exactly what you want unless you explain it well. I didn't know you wanted the user to be able to put the pairs in different areas, but BatVink has a good way to do that.


Hippopotomonstrosesquippedaliophobia-Fear of long words
BULLSHOCK 2
Retired Moderator
19
Years of Service
User Offline
Joined: 14th Jun 2005
Location: Shocking Bulls
Posted: 30th Jan 2006 21:41
wait a minute...then how does fpsc do it?

the fpe files dont use separate lines for the values and the variables...

hmmm....


but thanks guys for your help.

NeX the Fairly Fast Ferret
19
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 30th Jan 2006 21:56
Here's my classic level format:



The code:




At least farting ferrets are better than stinky stoats.
Joh
20
Years of Service
User Offline
Joined: 5th Jul 2004
Location: Malaysia
Posted: 30th Jan 2006 22:56
The FPE files are text files and yeah the info is stored like so

size=10
weight=25
color=1

so pretty much you're down to parsing text, by line. Try what Ferret's got, should work.

!
BULLSHOCK 2
Retired Moderator
19
Years of Service
User Offline
Joined: 14th Jun 2005
Location: Shocking Bulls
Posted: 31st Jan 2006 01:56
thast what i was doing in the first place, i just posted here to see if there was an easier way...

so that means i have to manually type that out for every single command.

it also is going to lengthen the code quite a bit, not to mention take a long time.

but thanks everyone for theire help.
i appreciate it.

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 2nd Feb 2006 23:43
regarding the code in the first post of this thread, to get the file lines into an array: iirc Load Array() does this in one call, but I dont have dbp installed so I cant check on that. You may want to check that out.

SORRY UR NOT COMEDIAN

Login to post a reply

Server time is: 2024-09-24 15:24:24
Your offset time is: 2024-09-24 15:24:24