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 / string command question

Author
Message
Plugged
22
Years of Service
User Offline
Joined: 30th Nov 2002
Location: Hertfordshire
Posted: 26th Oct 2005 17:49
hi gives i'm not too hot on text commands and how to use them. Baically i need some code to sort through a string called text$(what) and when every the string "%d%1" is found replace it with charaname$(1) then once all the replacements have been made put it backing to text$(what), ohh and the number at the end of %d% is the element number of the charaname$() array so
"%d%1" should be replaced by charaname$(1) and
"%d%2" should be replaced by charaname$(2) and
"%d%3" should be replaced by charaname$(3) and so on...

can any one help me or at least point me in the right direction.


Work Hard; Play Harder ;
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 26th Oct 2005 18:18
Plugged,



This does exactly what you mentioned you needed, all up to my understanding of what you needed, that is.



+NanoBrain+
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 26th Oct 2005 23:17 Edited at: 26th Oct 2005 23:18
... and if Nanobrain's solution doesn't solve your problem, there is I think 17 string functions in my remarkably aptly name 'String Function Collection' on the downloads page of my web site. (Link at bottom of post).

TDK_Man

PS: Nanobrain, have you received any of my e-mails recently?

NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 27th Oct 2005 05:28
TDK,

Well, accually I have not. Sorry. I am no longer with AOL, and I have not created another web email yet. Do I need to do so, that you may email me anything?



+NanoBrain+
Plugged
22
Years of Service
User Offline
Joined: 30th Nov 2002
Location: Hertfordshire
Posted: 31st Oct 2005 17:27
Nanobrain example is good but i believe that will only work if the special string is at the start as in

"%d%1 hello my name is Nanobrain"

where in the game a string could come up like

"Hello %d%1 me and %d%2 are just going to look for %d%3, yeah and %d%2 said he just saw %d%3 with %d%4 just over that hill"

now this is an extreme example but i thing it proves the point. hopefully this code should then replace that string with.

"Hello Fred me and Huw are just going to look for Dave, yeah and Huw said he just saw Dave with Lizzie just over that hill"

this assuming
charaname$(1)=Fred
charaname$(2)=Huw
charaname$(3)=Dave
charaname$(4)=Lizzie

okay
cheers
Woody


Work Hard; Play Harder ;
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 31st Oct 2005 19:02 Edited at: 31st Oct 2005 20:07
Plugged,

You should have been a bit more specific at the beginning of this post. You did not mention anything about searching a whole sentence previously.



This code has not been tested, but I do not have time to do so now. With this code, the name array can only go up to a value of 9, from 0. However, that can easily be fixed. Let me know if the code does not work properly.

[EDIT]
IS there not a better way than placing these characters into a string and then evaluating the string? There must be a better way.

[EDIT]
Wouldn't it be easier to store the sentences in a text file, like the example below? (The first line enables you to recall a sentence word group{it is the number of the sentence in step value})



In this case, you would need the program to know what names to fill in the gaps. This would be much more efficient than evaluating each character in an entire string.



+NanoBrain+
Plugged
22
Years of Service
User Offline
Joined: 30th Nov 2002
Location: Hertfordshire
Posted: 1st Nov 2005 23:56 Edited at: 2nd Nov 2005 00:01
sorry i can't test the code right now, see i have a script for all the cutscenes in my game and the problem is i am letting the player name the characters so the saved script needs to be changed for each different run so it is in sync with the character name array which will go up to 6.

cheers
Plugged

p.s. sorry about the first post not mentioning searching

EDIT
i just thought if it makes it any easier the %d% was just something i made up as something i thought would never come up in the script, if there is something else that i could use.


Work Hard; Play Harder ;
Hobgoblin Lord
19
Years of Service
User Offline
Joined: 29th Oct 2005
Location: Fall River, MA USA
Posted: 3rd Nov 2005 05:16
Plugged;

Here is a search and replace i came up with




I use <keyword> to denote various replace functions and set an if for whatever they happen to be. I use the page$() array to reformat the text from the story$() array to the appropriate width since a long replace string could send the end of your text off the screen. the charinline is to count the number of characters per line before switching to a new one which it will oly do at a space. I usually read the text in from notepad, this seems to work the best for me anyway. I hope this helps, it works really well for me but i use about 40 TAGS for replace effects.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 3rd Nov 2005 06:00
Plugged:

Did you check out the string functions I mentioned?

Those, along with NanoBrain's advice might solve your problem. (One of the functions will split up a sentence and place each word in a string array).

However, I too may have misunderstood what you were after!...

NanoBrain:

Yes, could do with speaking to you at some point if possible. MSNM is also a possibility too.

TDK_Man

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 3rd Nov 2005 06:50
Back when BBSes were the only kind of "internet" we had I used to use renegade pipe codes all the time for color... so when I wanted to color text in Darkbasic one of the first things I did was to make a text coloring function.

This is a modified version of that text coloring function. In this the coloring part has been replaced with text.

Plugged
22
Years of Service
User Offline
Joined: 30th Nov 2002
Location: Hertfordshire
Posted: 3rd Nov 2005 13:06
Thanks guys i thing you all got good ideas and i'm sure all your code works but i think i'm going to go with Grog Grueslayer as it is the easiest to understand so if it doesn't work at first i have the most chance of correcting it and modifing it.

cheers
Plugged


Work Hard; Play Harder ;

Login to post a reply

Server time is: 2025-05-22 15:01:38
Your offset time is: 2025-05-22 15:01:38