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.

DarkBASIC Professional Discussion / Help with Reading Data

Author
Message
spike 132000
18
Years of Service
User Offline
Joined: 7th Nov 2007
Location: Nottingham, UK
Posted: 20th Sep 2011 02:01
Hey Guys, really pulling my hair out over this one

I have managed to load a file and get a string from it, the string is like this



how do I split it at , and make each of the parts useable. I can't find a split command anywhere, and im not being a cheap skate or anything, but im looking to avoid additional plugins. I must be missing something but im sure there must be a split string command already!

Thanks!

http://pspguides.forum5.com - A Great PSP Community
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 20th Sep 2011 03:53
Hi Spike!

You need to make use of the MID$, LEFT$ and RIGHT$ commands!

MID$ returns a single character from a specified point within the string, LEFT$ and RIGHT$ grab either the left-hand or right-hand side of a string.

So, for example, if I had a string called TEMP$ and it contained "CUMQUAT" I could use this sort of code:



You can also combine it with FOR\NEXT loops to pull at specific areas of a string dynamically. For example:



I hope this was illuminating!

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 20th Sep 2011 06:02
Another method I think would work is to use the TOKEN commands. They're probably the simplest method from what I've gathered.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 20th Sep 2011 06:20 Edited at: 20th Sep 2011 06:21
I don't know if there's a way to edit my previous post, but I came up with a quick example just now feeling my prior statement wasn't enough for justification.

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 20th Sep 2011 06:43
Ah, of course. Da_Rhyno is correct. That should work nicely.

Also, Da_Rhyno, the button to edit your posts are just below your display picture

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 20th Sep 2011 06:50
Lol, thanks. I figured that out shortly after I posted.

However, now I wish there was a way for me to delete the unwanted post.

But yeah, a few weeks ago I was looking to create an OBJ loader in DBP, and coming from a background of FreeBASIC I figured "Hmm, why not just port it over since it has the same string commands?"

Well, easier said than done. You see, the commands might be the same, but the parameters are different and what the commands do is different. So I then looked into the token commands, and they worked like a charm.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 20th Sep 2011 07:37
Yeah, it was a bit of a facepalm moment for me when I saw your post lol

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
spike 132000
18
Years of Service
User Offline
Joined: 7th Nov 2007
Location: Nottingham, UK
Posted: 20th Sep 2011 10:22
Thank you very much guys!

How would I put all the data in to an array cos there are about 800 of these lines :S

Say for example

SS(X).Id= First Item - 1
SS(X).Name= Second Item - "String"
SS(X).Type = Third Item - "R"
SS(X).X = Forth Item - 123
SS(X).Y = Fifth Item - 456
SS(X).Z = Sixth Item - 789

http://pspguides.forum5.com - A Great PSP Community
Sequence
15
Years of Service
User Offline
Joined: 16th Mar 2011
Location: Canada
Posted: 20th Sep 2011 11:13
Hi spike,

I think the problem is that, when you OPEN the file, is when you should assign the items to variables.

Open the file then, the manual is kind of vague as to whether more than one variable can be read at a time but here is how if you have to do it "manually".

Read file 1,level
Read file 1,Name$
Read file 1,item$
Read file 1,hit_points
Read file 1,experience_points
Read file 1,money

and then
level will be 1
Name$ will be "STRING"
item$ will be "R"
hit_points will be 123
experience_points will be 456
money will be 789


You SHOULD be able to read all the variables in one line of code, though.

I was using AMOS Professional before this and the Mid$ command was able to take a string from the middle of a string, all the way to the end of it, if need be; you could take a variable amount of characters at a time, not just one character at a time.

If all the "1"s are in the right place, it'll work like a charm.
Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 20th Sep 2011 11:17
There is a split string command in IanM's Matrix1 plugins. They are free, so perfect for people that dont want to be a 'cheap skate'

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 20th Sep 2011 11:20 Edited at: 20th Sep 2011 11:22
Quote: "You SHOULD be able to read all the variables in one line of code, though."


yeah Ian M's plugins have a better mid$.

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 20th Sep 2011 11:21 Edited at: 20th Sep 2011 11:23
I know you want to "avoid additional plugins" but the one that will give you what you desire (a SPLIT STRING command) is IanM's Matrix1 Utilities Plugins. The output of that file looks like it's a CSV file so you may want to use IanM's SPLIT CSV STRING which does the same thing but you don't have to type which characters you want to separate the string by because it's tailored to remove by commas and automatically remove quotes.



If you don't have IanM's Matrix1 Utilities Plugins then you get to enjoy the commands you've been dreaming about.

https://forumfiles.thegamecreators.com/download/2257747

Edit: Scraggle beat me.

spike 132000
18
Years of Service
User Offline
Joined: 7th Nov 2007
Location: Nottingham, UK
Posted: 20th Sep 2011 21:06
Ok, so I have



But I keep getting error: Cannot perform 'integer' cast on type 'TEMP3' at line 35.

Help :S

http://pspguides.forum5.com - A Great PSP Community
spike 132000
18
Years of Service
User Offline
Joined: 7th Nov 2007
Location: Nottingham, UK
Posted: 20th Sep 2011 21:25
and i've also tried:



but now I get: Cannot perform 'integer' cast on type 'TEMP3' at line 44.

http://pspguides.forum5.com - A Great PSP Community
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 20th Sep 2011 21:26 Edited at: 20th Sep 2011 21:34
Try using an array of types.


zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 20th Sep 2011 21:34 Edited at: 20th Sep 2011 21:40
Is it just me... or does anyone else think it's time that IanM's Matrix 1 Utils should be downloaded with DBpro?

It would be great if the DLL/commands were just a part of Official DBpro, but seeing as that won't happen I think think the next best thing is; it should be "clearly mentioned" right along side the upgrade of dbpro as a free enhancement pack.

I honestly feel that it's "THAT" important, and people shouldn't have to wait until they stumble upon it in a thread. I can't see it hurting anything to just have it as "you may be interested in this third party enhancement..." right along side the download of Dbpro or the upgrade. Or perhaps even part of the OFFICIAL download, with an option to install.

Your signature has been erased by a mod please reduce it to 600 x 120.
spike 132000
18
Years of Service
User Offline
Joined: 7th Nov 2007
Location: Nottingham, UK
Posted: 20th Sep 2011 22:01
Thanks alot Da_Rhyno, you are a ledgend!

http://feedit.me - Live feed platform, useful for events and shows!

Login to post a reply

Server time is: 2026-07-10 15:31:02
Your offset time is: 2026-07-10 15:31:02