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 Discussion / Alternatives to String Variables

Author
Message
Brick Break
User Banned
Posted: 2nd Jul 2009 22:16
Hey guys, I'm working on a game engine/script loader that I will post in the WIP section once I add more functionality, but first I need to push the maximum size of a script up a little bit. I think variables are somehow capped off at 255, which would be a problem for scripts 256 characters and up. I have it set up to load the entire file into a string, replacing each linefeed with a semicolon. I don't want to have to change that, because that system is fundamental to the speed and ease of use of my program. So, I need some way to store larger string values. Help?

Permanoobs are awesome.
Brick Break
User Banned
Posted: 3rd Jul 2009 01:46
Since there isn't much activity, I decided it's OK to bump. Help would be great, because if I released my engine right now, you'd all be stuck with a 255 character limit.

Permanoobs are awesome.
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 3rd Jul 2009 02:11
You mean like a system that can load TEXT and display it? Ive already done that, if you want to look at it.

Your signature has been erased by a mod because it was too big.CHANGE IT OR DIE!!!!!
Brick Break
User Banned
Posted: 3rd Jul 2009 02:14
@DD- No, that's not what I mean at all. I just want to know an alternative to string variables that holds more data.

Permanoobs are awesome.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 3rd Jul 2009 02:29
string arrays may be a possibility, you can dimmensionalize string arrays in the same way as regular:

dim array$(size)

and each section holds a string

Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 3rd Jul 2009 02:31
But can you hold more than 255 chars with this?



Your signature has been erased by a mod because it was too big.CHANGE IT OR DIE!!!!!
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 3rd Jul 2009 02:35
no but each section can hold 255 characters, then what you can do is fill each empty section with an odd character like ~ that you wont ever use in text

then just loop through each secion until you encounter that symbol

Brick Break
User Banned
Posted: 3rd Jul 2009 02:36 Edited at: 3rd Jul 2009 02:38
@DD- I'll test it.

Guys, all I'm asking is a way to have more data in a string, that's all.

EDIT: Oh, didn't see that someone else posted. Um, that's not what I'm looking for.

Permanoobs are awesome.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 3rd Jul 2009 02:39
ok, just pitching ideas out here

Brick Break
User Banned
Posted: 3rd Jul 2009 02:42
@That1Smart Guy- Got any more?

Permanoobs are awesome.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 3rd Jul 2009 02:48
ill think on it

Brick Break
User Banned
Posted: 3rd Jul 2009 03:16
Look, I think the only way to do it is with a memblock. How can I use a memblock to store string data?

Permanoobs are awesome.
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 3rd Jul 2009 04:02
Memblocks.........never used 'em.

But no, You cant store more than 255 in an array String, I dont think......

Your signature has been erased by a mod because it was too big.CHANGE IT OR DIE!!!!!
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 3rd Jul 2009 04:18
each section of a string array can hold 255 chars, so a 4 section array can hold 255*4 = 1020 characters (i think)

hhhhhmmmmmmmmmmmmmmm memblocks....... hmmmmmmmmmmmmmmmmmmm

ill keep thinkin on it

Brick Break
User Banned
Posted: 3rd Jul 2009 05:09
I know that you can allocate as much memory as you want in a memblock, but I don't know how to use one in place of a string variable.

Permanoobs are awesome.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 3rd Jul 2009 06:19
im working on a few simple functions allowing this to work, im close to a breakthrough on them so dont give up on me!!

Brick Break
User Banned
Posted: 3rd Jul 2009 06:23
@That1Smart Guy- I won't. I'm looking forward to this... Hey, once you've got it, go ahead and post a thread about it! (but link to it from here of course) Ooh I can't wait

Permanoobs are awesome.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 3rd Jul 2009 06:57
basically heres how it works, i have 3 functions:

MakeTextBlock(blocknum,numberofchars)

this one just creates a memblock of the same size as numberofchars (honestly this one really is unneeded but why not have one?)

WriteToTextBlock(blocknum,string$)

this one goes through each memblock byte and writes to it the ascii value of each char (however since string$ can only hold 255 chars, to get more you need to call this function multiple times, not to worry it will automatically know where to begin the writing process so data wont be overwritten

and PrintTextBlock(blocknum,x,y,charsperline)


first it sets the cursor (the top left corner of where the first print will go to) to x,y

then it loops through the memblock until all the text has been written, going in increments of charsperline (since print can only run 255 chars max at a time I wanted a way to control how many per line)

then it prints that line

the only rule involving this is your string CANNOT contain the ~ sign, (not the minus, the shift + ` one) because thats the character that signals the end of the string, not too big a problem since that character is rarely used


sorry its not done, still working some bugs out

sounds cool though doesnt it?

That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 3rd Jul 2009 07:14
ok here they are, if you need any other functions just holler and ill whip em up

as I was making these I began thinking "this may be pointless because you still have to load the memblock 255 characters at a time" but then im like, "eh, its better than nothing" so here ya go:



pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 3rd Jul 2009 08:18 Edited at: 3rd Jul 2009 08:43
You could do something like this:

This just shows how my string becomes unlimited and how to write to the string, you'll have to change the rest on your own.



EDIT:
Changed it, now its a function:

Brick Break
User Banned
Posted: 3rd Jul 2009 19:45
Guys, your functions are very confusing. Like they say, it's easier to write code than to read it.

Permanoobs are awesome.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 3rd Jul 2009 19:59
how are mine confusing?

you MakeTextBlock(blocknum,numberofcharacters)

blocknum being the memblock number to be created

then to load it you use WriteToTextBlock(blocknum,string$)

blocknum being the number of the memblock, string$ being the string to be added (it will automatically be added at the end of the previous string if you add more than one)

then to print it just use PrintTextBlock(blocknum,x,y,charsperline)

blocknum again being the memblock number, x,y is the coordinate to start the printing and charsperline is the number of characters you want on a single line of text

Brick Break
User Banned
Posted: 4th Jul 2009 00:23
@That1Smart Guy- I don't want to print it. I want one really huge string variable. How could I do that?

Permanoobs are awesome.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 4th Jul 2009 00:27
You can't add more than 255 characters to a string, or you get a "string overflow" error. You have to split your strings up, and when you print them you put them together in the correct order.


Make the path of your enemies easier with Waypoint Pro!
Brick Break
User Banned
Posted: 4th Jul 2009 00:30
@TheComet- Is that the verdict? It sounds like the best way is to have each line in an array dimension.

Permanoobs are awesome.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 4th Jul 2009 00:49
well yeah that probably is the best way, i went kinda overboard on it, o well

Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 4th Jul 2009 00:57
An Array....

Your signature has been erased by a mod because it was too big.CHANGE IT OR DIE!!!!!
Brick Break
User Banned
Posted: 4th Jul 2009 01:09
OK, so I might have a lot of rewriting to do. *sighs* Oh well, it's not like I have a life.

Permanoobs are awesome.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 4th Jul 2009 01:24
You just want one long stream of data from the file stored in memory? How about:



And to change line feeds and carriage returns to ; (though there will be 2 if the file saves a carriage return and a line feed)



Enjoy your day.
Brick Break
User Banned
Posted: 4th Jul 2009 01:27
@Latch- Then how would I read from the memblock?

Permanoobs are awesome.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 4th Jul 2009 01:41
It depends on the goal. What size chunks of data are you reading? are the data chunks delimited (separated by specific character) by more than just the end of line ; ?

If the data is stored as character codes (string data), then you retrieve it byte by byte using value=memblock byte(memblock number,position) just like my add semicolon code above.

The code contained in SmartGuy's PrintTextBlock(blocknum,x,y,charsperline) also uses this idea, though you'd change it more towards what you were using the data for.

Enjoy your day.
Brick Break
User Banned
Posted: 4th Jul 2009 01:43
@Latch- OK, I'm DEFINITELY using arrays now lol.

Permanoobs are awesome.
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 4th Jul 2009 01:59
lol. can u explain a bit more latch?

Your signature has been erased by a mod because it was too big.CHANGE IT OR DIE!!!!!
Brick Break
User Banned
Posted: 4th Jul 2009 02:09
It's OK, DD. I've decided to replace the semicolon system with arrays. It's a lot simpler than hassling with memblocks.

Permanoobs are awesome.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 4th Jul 2009 02:10
memblocks are fun though!!

Brick Break
User Banned
Posted: 4th Jul 2009 02:15
Quote: "memblocks are fun though!!"

Yeah...

Permanoobs are awesome.

Login to post a reply

Server time is: 2024-05-20 11:13:51
Your offset time is: 2024-05-20 11:13:51