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.

Author
Message
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 22nd Sep 2010 16:43 Edited at: 22nd Sep 2010 16:49
No, I already know how to use the Ink command

But, I'm not quite sure what I need to do, so that I can apply several different colors to different parts of the text that will be printed out in my text game.

Do I need to develop some kind of parsing routine and build that into my print statements? Or would it be easier to perhaps use a bitmap font? (I've seen fonts for games where the whole sheet was the font line in different colors) I really want to get color highlights in there, as I believe this will help readability a lot vs just the standard vanilla text color most text games sport.

The printing of a single room description alone could have key highlighted spots as large as 4 or 5 different colors (not the whole lines, just key words to draw your attention to important information). And a "con" system for mob difficulty by color would be nice as well.

Obviously its not something I want to be really hardcoded into the printed statements themselves (tags would work well though I think) that way they can be changed relatively easy..

Suggestions and ideas are appreciated.

The only idea I could think up on the fly, was a system of recognized tags (like HTML or whatever) around words, but not to the extent that the color is specified IN the tag, I think it should be that the tag says "make it this color" and then you can easily change the highlight for text with the same tag.

Once the tag is recognized, perhaps breaking the input stream up, applying the ink colors, and then reassembling it? Would that work?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Sep 2010 16:55
Quote: "No, I already know how to use the Ink command"


Quote: "Once the tag is recognized, perhaps breaking the input stream up, applying the ink colors, and then reassembling it? Would that work?"


Sounds like you've answered your own question. Try it.
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 22nd Sep 2010 17:30
Well I only thought that up as I was writing the post..

Although handling the tag parsing part, I would probably need a little push in the right direction.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Sep 2010 19:08 Edited at: 24th Sep 2010 12:43
Quote: "Although handling the tag parsing part, I would probably need a little push in the right direction."


OK, I'll see if I can come up with a simple example.

Edit Here you go.



Interestingly, this seems to have highlighted a DBPro bug.

Edit Even more interesting - it wasn't a bug just a Help file obscurity in the Help for val().
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 22nd Sep 2010 22:17 Edited at: 22nd Sep 2010 22:21
Back before the internet I made a couple of Renegade BBSes where I learned a technique to color text using pipe codes in the middle of the text using Renegades own coloring routine rather than ANSI. When I applied it to QuickBasic it worked flawlessly... Darkbasic Pro is the same way.



I added a regular basic MID$() function since I know you've turned off IanMs text commands. If you turned it back on just change "Mids" to MID$ and delete that little function. Also you can change the symbol used to anything you want if you're planning on using the pipe character in your regular text.

Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 22nd Sep 2010 22:27 Edited at: 22nd Sep 2010 22:28
Thanks those are neat examples

I'll play with them and see what I can do once I figure out my stupid infinite loop problem! (diff thread)

I like the idea of pipe characters, it's exactly like how I want to do

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Sep 2010 03:32
You could also try looking at my syntax highlighter code:
http://forum.thegamecreators.com/?m=forum_view&t=96755&b=6


"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke
sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 24th Sep 2010 12:15
If you are doing string handling like that then you should really use Ianm's utils because it makes stuff like this really easy:

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 24th Sep 2010 18:39
That's an awesomely simple way of doing it! lol Much better than the code I did for someone else a few months ago.

My signature is NOT a moderator plaything! Stop changing it!
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 11th Oct 2010 19:15 Edited at: 12th Oct 2010 00:03
Ok.. So the thing I noticed about all these wonderful (they truly are) examples, is they all seem to deal with use print or text statements at the time the color is applied..

But I realized, I need something different.. Because anything to be "printed" to the screen, is actually a string that is stored in an array, and then a range of array indices is printed to the screen.


There is no way for me to apply Print/Text assignment commands in real time like these examples do..

IS it possible, to apply an RGB color to a string variable, and have that text retain its color, when it is printed from the array? No matter -what- the text color is currently set to?

I hope that came out clearly...

If its not possible, I guess the only way to get it to work is to change the way I am displaying my scrolling text...

I saw a method, I think for playbasic, where I think you essentially make an "image"/copy of the current screen where your text is, and then shift that image in such a way so that a line of text will dissapear, and a new blank line will be available at the bottom.. I think it was an in-game console (like Quake and many other FPS games have) example, but I don't think it supported scrolling back up.

I suppose I could try and code something like that if I needed, but I've never worked with image commands or anything, and not sure how well the idea would translate.


Late Edit: Probably obvious to everyone else, but I have decided I am gonna try and rewrite my entire printing routine, and how I'm printing my array lines, so that every line coming through gets parsed and I'm gonna have to include some kind of tags within the Room text as I write it. Fair enough..

But any ideas to help along the way are cool

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 12th Oct 2010 00:30 Edited at: 12th Oct 2010 00:34
Here's an expansion of the example before. It's really true the devil is in the detail because this started at about 30 lines before all the tweaking Hopefully commented enough, just ask if not.

edit: This would be really slow displaying all the text every frame, but I guess you will only update the window when new text is added or the user scrolls.

Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 12th Oct 2010 00:44 Edited at: 12th Oct 2010 00:44
Slade,

That is a truly, awesome, piece of code.. I don't know if I will/can use it Verbatim but I will study it closely and use it to the best of my ability. I hope it will teach me what I need to know.

Thanks for your effort!

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 12th Oct 2010 11:45
Quote: "Thanks for your effort!"

Yw, I enjoyed writing it

Quote: "I don't know if I will/can use it"

Maybe you could show a mock-up of what you are ideally trying to achive then it could be tailored to fit what you need. Or are you determined not to use matrix1 utils? The rotate array() and word splitting could be written as db functions but IMO if you are writing a text based game you would be mad not to use matrix1 because it has great string manipulation commands!
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 12th Oct 2010 13:49 Edited at: 12th Oct 2010 13:50
No, no. I have no problem using Matrix Utils.

What I mean is, I am trying hard to figure things out for myself instead of just "asking for code" to copy and paste and make a program from.. So I try to study the examples people provide and either adapt them to what I want to do, or at least extrapolate some good ideas from them to incorporate into a different method of doing it that I understand (personally) from the ground up.


A mockup might be helpful I suppose.. But its nothing I haven't said already. A lot of the examples given already, are pretty much covering the mechanics of how I should be doing it, although I was hoping to find a way to not have to hardcode color tags into my data as I type it into the world builder.

I have ideas for a middle-ground solution, but I won't know how that pans out until I rewrite my print routines to adapt to that.

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 12th Oct 2010 14:28
Quote: "method of doing it that I understand (personally) from the ground up."


With you now, and for sure the best way in the long run.
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 12th Oct 2010 16:47
I do have a slightly different tangent I wish to inquire about. Also about highlighting..

One feature of a particular MUD client (proprietary) was the ability for the player to set their own highlights, on any letter/word/phrase they chose to.

Is the process for doing something like that, nearly the same, only modified to check against a REGEX, vs looking for a tag? You're still reading one line at a time and reassembling it by word?

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 12th Oct 2010 17:22
Effectively that's a simple syntax highlighter.

Just before the word is output with `text x,y,wrd$`, check if the word is on your list of `special` words and modify the colour accordingly. You could use an array of words/colours or some other user-editable list.

If you wanted to be more efficient, then you could put the word checking and colour code inserting in the addTxt() routine so it is only checked once.
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Oct 2010 18:20 Edited at: 12th Oct 2010 18:21
Quote: "What I mean is, I am trying hard to figure things out for myself instead of just "asking for code" to copy and paste and make a program from.. So I try to study the examples people provide and either adapt them to what I want to do, or at least extrapolate some good ideas from them to incorporate into a different method of doing it that I understand (personally) from the ground up."


We appreciate that you don't want to just copy and paste our code into yours but when you say "try to study" do you mean you just look at the code and not run it in Darkbasic Pro to see what our code snips do?

Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 12th Oct 2010 18:27 Edited at: 12th Oct 2010 18:31
It depends on the situation. Sometimes I can gather enough of what is going on that I don't need to run it, and can start writing my own stuff to do test runs with.

In other cases, I'll run code and see what it looks like, and sometimes I might even run through it in step-through mode.

TDK's scroll box for instance, I ran and played around with several times, tried and failed to write my own analogues to what it was doing, and eventually after banging my head many times, I came up with the stuff I'm using today that is mostly written by me.

The only real copy and paste job I've done was a non-blocking input routine I got from the Code Base. I figure the best way to teach myself is to "type it all in" myself, so I get used to reading DB's particular syntax and can visualize what code is going to do more easily.

I know that its not a bad thing to ask people to write stuff for you, when they know you've tried hard. But I have a guilt complex, and tend to be so honest that it becomes a fault..

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Oct 2010 02:59
Quote: " is they all seem to deal with use print or text statements at the time the color is applied..

But I realized, I need something different.. Because anything to be "printed" to the screen, is actually a string that is stored in an array, and then a range of array indices is printed to the screen.
"


Ok, you've lost me. The only way to display text is using Print or Text (unless you used bitmap fonts of course). And yes the color must be applied as the text is being displayed, it's kinda how it has to work. My only thought as to what else you could possible want is to have the color codes for certain text already specified without having to re-parse it each time you display it? But in either case, the text must be parsed in order to use different colors.

What you could do is use another array containing "ColorElements", which would store a color and the start and ending index within the larger text for which to apply that particular ColorElement highlight.


"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 13th Oct 2010 16:52
I've moved past that issue as I started to get a better understanding of how color parsing works.


But for the sake of un-losing you.. Basically I was wishing it were possible to say, parse a string of text with color codes, and then reassemble that string into a new one, with colors intact - and no matter what, have the state of those colors remain intact..

So basically being able to "store" a colored piece of text internally was what I was trying to describe. The benefit being, printing that string in the future, requires no more parsing, and it just flat out, shows up with the colors that were applied.

To visualize the idea...
Think of it kind of like saving the pixels in a picture, it has its palette and when you load it and display it any time in the future, every pixels knows what color it is...

I'm guessing that's just not the way "it works" though, so I've gone ahead writing my new display routine with the parsing stuff, and hopefully it'll come out nicely.

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 13th Oct 2010 18:12
It's just like Phaelax said. The only way to retain the color of text without using color markers in the string is to make every line an image. Though in doing that you're no longer working with text at all.

You could create an array that stores text in one element and the color for that whole line in another element but you would loose the ability to color individual words. You wouldn't have to place each individual character because you aren't allowing color changes, just change the INK before printing the string.

There are some advantages to going through each character. Like instead of regular text you can use bitmap fonts which need to be placed individually to get the proper pixel distance from each letter. Bitmap fonts can also be colorized easily if the bitmap font starts out colored white. Adding images to your text can be as easy as the color markers... you just use another character for an image marker with an image number instead of a color number.

Whatever method you decide to do the user isn't going to know how sophisticated it was coded... all they'll know is it's a cool Text RPG with colored text.

Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 13th Oct 2010 19:25
Yeah I did think about using bitmap fonts in the beginning, but decided not to for some reason I can't remember.

Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 14th Oct 2010 06:43 Edited at: 14th Oct 2010 06:51
Ok... I must be missing something really obvious, here?

I'm really tired at the moment (horrible tooth ache, hope the dentist can squeeze me in tomorrow!! )

But so far this will work work, IF I use specific static values in the FOR loop, in the Display Function. I have looked at my own previous code from a working loop, and from other examples in this thread and TDK's original code I used as a learning base.

I can't seem to figure out the math to correctly get it to display the number of lines up to the box, and whats weirder is if I try using non static values to do some calculations to that effect, I get a completely blank display.

I'm sure I am missing something real obvious here - or my syntax / logic is fudged at some point..? meh? Hopefully this will be a minor correction.. I don't mind using a static value at all but that is not how it's -supposed- to work and everyone else seems to be able to do this but me...lol

This is mostly test code, and I'm in the process of rewriting my main Display function - I haven't added in the tag parsing code yet or anything, so don't let that distract you.


The one other thing I noticed, even when changing my original function, to display a different part, of a much larger array, is I could NOT get it to work unless I made a specific "LineHeight" variable, instanced at 0, and then incremented it by 1 with each pass of the FOR loop.. This was not necessary in my original function (a 20 element Array), nor TDK's function, or a couple others I've seen. I really suck at math so I don't know why this is.

Also, there may be a few unused elements declared in the UDT definition. This was built using Slade's contribution earlier in the thread as a template. There is a lot of stuff in his code that has to do with var.CurLin - and a bunch of stuff to do with an AddText() function and chunks, I don't want to go down that route as I already have a nice, working method for adding text into my array.. So that is why that part is absent. It shouldn't be affecting the code, though, I don't think.

As you can see it's a slow learning process for me

Comments on changed code that explain what is happening are GREATLY appreciated.




And now I have to slink off to bed to TRY and get some sleep before work in 6 hours... make it through a 3 hours shift and then hope the dentist can see me some time tomorrow.... ugh

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 14th Oct 2010 08:08
Is this what you're looking for?



The only changes I did were moving the defining of TextBox.TxtHght up one line, used that variable to calculate the number of lines, added StartLine=TextBox.maxLine-TextBox.numLine, and used StartLine and TextBox.maxLine in the FOR/NEXT loop. I also removed the defining of LineHeight because variables are automatically created as integers that start out at zero the minute their first used. You don't really need the "AS INTEGER" outside of a UDT... especially if it's going to be defined as zero.

Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 14th Oct 2010 19:04 Edited at: 14th Oct 2010 19:12
Ahh, dude. You're my Hero.

yeah.. I know I technically don't need to define something in that specific case, but I'm trying to teach myself good programming practices. That might help if I ever (...ever) graduate to a strongly typed language with more rigid syntax.


Now that I think about it...I guess DB could be considered a "strongly typed" language..? Seems different people have different ideas of what it all means, heh.

Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 14th Oct 2010 20:13
If you could send all the text to a web page, changing the color, the font, font size, etc. would just be a matter of including the proper html tags.

Can DBPro have a web browser as part of its window? I think I saw something about BlueGUI having one.

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 14th Oct 2010 22:40 Edited at: 14th Oct 2010 22:44
I looked at your code and commented a couple of changes with reasons, hope that's ok.

I thought the original spec for your text display was something like this:
A display window of text that scrolls as new text added.
A greater size of history so the player can go back and look at earlier actions.
Being able to just send text to the window without worrying about the window size. ie. Automatic word-wrapping.
Text colouring. ie. Automatic highlighting for mobs, rooms, objects etc. Plus definable colouring in descriptions / narrative or whatever.

If you want to have formatted text of any kind then you are talking about a parser somewhere along the line. Other languages have additional specialized print functions that parse special tags and `expand` them into formatted text. Whatever method you use to finally display your text (images, text, bitmap fonts, whatever) you will need to parse your text initially and have some method of specifying formatting. Your example of a palette illustrates the same point. The palette is effectively the parser for the pixel data. (As a lookup table) It tells the display routine how is should present each pixel.

Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 15th Oct 2010 01:04 Edited at: 15th Oct 2010 01:07
Thanks for your input. I haven't yet built the parsing into my display function, as I had the problem with getting it working just right. But I'm pretty sure I've got that fixed with Grogs helps, plus some ideas I had that I had not considered before.

Just to respond to your one comment (why the -1 on Text Height?) I did that for spacing reasons. I prefer the slightly tighter spacing that the -1 ads for the time being, although I hadn't decided if that would be permanent or not. TDK's original scrolling text box used the same -1 if I recall correctly. So it's always been second nature for me to throw that in.

What I'm planning to do is add on to this new Display function, so that it will find and parse out the color tags.

My add text function actually does do this, to a minor degree, but only for purposes of finding and removing those tags, so it can check the line length of the "real" amount of text in the string and decide whether or not to split it. In terms of logic that makes the most sense for me. The function to add text handles the meat of things, makes sure lines go where they are supposed to, etc.. The Display function is purely concerned with showing that text, making sure it is viewed properly.


Rich's point about sending it to a web browser was a rather fair one too. However in the end, its going to have to be parsed either way. So I'm just sticking with the current method

Login to post a reply

Server time is: 2026-07-23 04:54:58
Your offset time is: 2026-07-23 04:54:58