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 / Screen Text and Coding Practice

Author
Message
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 20th Aug 2013 18:14 Edited at: 20th Aug 2013 18:32
Okay, for now here is a temporary solution:


This also requires rearranging the order of the bias text data:


Full Code:




The gluteus-maximus mammary-gland formally known as OBese87.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 21st Aug 2013 20:36 Edited at: 21st Aug 2013 20:43
Quote: "Why do you use absurdly long variable names, like 'NightWatchMainMenuSelection'? They are not helpful."




Oh OK, are not long descriptive names helpful. I thought that long descriptive names where a good thing; I always forget what abbreviations mean in months past if not used often; and there is no namespacing without UDTs or tip text remarks available.

I would have commended him for such a specific descriptive variable name,

Why is it bad? Do you mean that it creates some kind of clutter or is too much to read?


Quote: "** EXPLANATION OF THE SILKEY FUNCTION **
SILKEY, by Silverman/Libervurto, is a function for simplifying the use of Autonomous Assignment Variables (AAVs).
AAVs are self-governing variables, they instruct their own assignment via additional data stored within themselves.
You do not need to understand the inner workings of AAVs in order to use this function, you only need to interpret the return values.
SILKEY was designed for managing inputs, so I will explain the return values in that context, but it could be used to monitor
the changing state of any boolean variable.

RETURN VALUES:

Value State
0 idle
1 newly pressed
2 newly released
3 held

These values may seem to be in a strange order, but the order becomes logical once you consider their binary representations and the fact
that SILKEY operates a FILO system, which records both the previous and current state of the trigger within the return value "




Fancy stuff.

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 21st Aug 2013 21:53 Edited at: 21st Aug 2013 21:55
Quote: "I would have commended him for such a specific descriptive variable name. Why is it bad? Do you mean that it creates some kind of clutter or is too much to read?"

It's overly descriptive. We don't need to call it 'NightWatchMainMenuSelection' because it is only ever used in the context of the night watch main menu. So we could call it "selection" — or "menuSelection", if there were some other type of selection occurring in the same block that we need to differentiate from.
Long names simply make the code harder to read, especially with prefixes like "NightWatchMainMenu-", where we have to read four words before getting to the actual use of the variable.

The name 'NightWatchMainMenuSelection' is also ambiguous, because the word "selection" could either mean an option has been highlighted or that has been submitted. I chose to change the word "selection" to "cursor", and since "cursor" on its own is ambiguous, I clarified that it is the "menuCursor". I actually called it "NWmenuCursor", but only so that it would be more recognisable to flamerator.



The gluteus-maximus mammary-gland formally known as OBese87.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 21st Aug 2013 22:49
OK

I guess I opinion differs

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 22nd Aug 2013 00:40 Edited at: 22nd Aug 2013 00:42
Quote: "I guess I opinion differs"

Does it really? I have explained that giving unambiguous names is important. Variable names should be as descriptive as they need to be in order to convey their purpose within the context they are used, no more, no less.

Here's an example of an insufficiently descriptive name:

To begin with, 'i' is perfectly understandable, since we are simply using it as a count variable, but later on we use it outside that context and it's not clear what 'i' refers to. Here's a better name for this usage:

Now we can tell from the name that the variable stores the first field of our array with a >0 value. This might not even have been clear to someone who had read through the entire code, when the variable was called 'i'.

Granted, that is a weird example.



The gluteus-maximus mammary-gland formally known as OBese87.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 22nd Aug 2013 01:06 Edited at: 22nd Aug 2013 01:31
Yeah; just felt that 'NightWatchMainMenuSelection' was a high-level programming object; infrequent. Something not as in your face obvious as [I] in a for loop. Some of my for loops contain rather long iteration names.

The meaning of NWmenuCursor could not register in my brain unless there is only one menu name begining with NW. What if there where 50 odd menus in the whole game, you would still identify them that way?

By the time I got to 30,000 lines, all them short names and abbreviations started to do my head in. So I started again...

The only short names I use are for low level programming; as you stated with [I] in the for loop; or in my case OSZX which is a constant returns an arbitrary object size on the x axis with actual size field set to true. Meaningless name, but its a part of my vocabulary because it gets used practically every 15 minutes.

Sometimes an abbreviation such as pc is used locally to store the player count; but only because the lifetime of it is brief and the surrounding comments and set of commands show what the variable is for.

Felt that neither NWmenuCursor or NightWatchMainMenuSelection could not be part of a work-flow vocabulary; or in other words, I am too dumb to memorize more than a few 100 abbreviations that get used less than one day a week.

Quote: "We don't need to call it 'NightWatchMainMenuSelection' because it is only ever used in the context of the night watch main menu."


I see that point clearly now; it is true.

I always analogize my source code with London city; a place to get lost in rather easily had it not been for descriptive mapping and signage.

I guess this rubs off on how I view variable names.

So be it.

Indeed, cursor is more apt than selection if the object does not store the selection, but rather stores a location in the menu. I tend to name things based on what they do or what they store; when this is not possible, it is time for a new class.

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 22nd Aug 2013 01:38 Edited at: 22nd Aug 2013 01:38
Quote: "The meaning of NWmenuCursor could not register in my brain unless there is only one menu name begining with NW. What if there where 50 odd menus in the whole game, you would still identify them that way?"

No, I would use the same 'menuCursor' variable for all menus, unless remembering the cursor position was beneficial: if the menu list was really long and there were sub-menus you could return from, for example. In that case I might give it a more descriptive name, especially if the variable was to be used outside of its "native" routine.

Descriptive names are definitely a good thing, but making them descriptive in as few characters as possible is the ideal. I mean, just try typing out "NightWatchMainMenuSelection" twenty times and see how quickly you tire of it.

Verbose names like "NightWatchMainMenuSelection" remind me of commenting like:

There is no need for a comments here. This is obviously a hang-up from the type of comments beginners are used to reading in tutorials.



The gluteus-maximus mammary-gland formally known as OBese87.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 22nd Aug 2013 02:11 Edited at: 22nd Aug 2013 02:27
True.

Although I am a copy and paste programmer; so I wouldn't notice much difference in typing long words. Most things here reside in a UDT in the DBP end of my game so I don't even type most names more than once.

This makes me think about my habit of using the Is and Has prefix:

Player.IsReady over Player.Ready. lol

IsReady just reads better to me.

I guess it is consistent with .Net naming conventions; but not your typical DBP one.

Player.Ready just doesn't flow with the way I like to read it. Even though it is perhaps the better name.

The longest variable name I have is likely to be SportsRoundsCurrentlyActiveStat.

It feels like it all saves me from having to write many comments, since the names read so well.

OK at least I chopped off the Statistics word at the end. But the currently word is redundant; but I only gave thought to this variable name for a few seconds, I did not care about it, so as long as it explains what it is.

Thinking of it, both SportsRoundsCurrentlyActiveStatistic and SportsRoundsActiveStatistic have two meanings either way.

I only have this written in my program twice, and I did not type in the second instance. All of my statistics are in an array so the user can select them and node scripts can query them. The only reason why I took the trouble of having a global variable is to store the array index for it.

on the contrary my shortest name is LG. It is a logging function, short for Log, which is reserved for the maths function.

Alot of Lee Bambers stuff has a mixture of long names with no title case, or really short ones like eleprof. I hate it lol.

Another reason for my hypernaming conventions is because my properties have prefix characters without underscores. Which is probably why abbreviations had to be dropped.

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 22nd Aug 2013 05:04 Edited at: 22nd Aug 2013 05:05
Quote: "This makes me think about my habit of using the Is and Has prefix"

I like those prefixes, they make it abundantly clear what sort of data they hold. You would be confused when reading: 'player.ActiveQuest', but 'player.HasActiveQuest' is clear that it is a boolean value; where 1 means the player indeed has an active quest.



The gluteus-maximus mammary-gland formally known as OBese87.
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 23rd Aug 2013 10:06
Quote: "Just for fun, I took screenshots of your original code and the updated code scaled down to font size 2."
lol I'm loving that.

Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 23rd Aug 2013 20:57
Hi, Sorry for being so quite.


The Mouse & Keyboard controls

The reason it's a mixture of both at the moment is that I haven't started implementing it in all areas yet and I thought I would start with the more simple parts of input than the more complicated part.

The Full Code

I've been getting another error which I don't understand why it appears which is this 'load image Tybalt,4,0,0' and happens on Line 275.

The Variable Names

The personal reason why I have them so long is because they are the first thing which jumps in my head so when I forget the name (which I definitely do) I can find it quickly by using the search for word feature built in and just find it in seconds instead of having to actually remember it. I also have them over the top descriptive for when I'm not overly awake I can just read it and know exactly what it does instead of trying to figure out what the abbreviation is. This is just what I prefer to use for some strange reason.

The Menus

I also like to say the amount of features I'm planning to have in this game will involve a lot of menu's and sub menu's which means that having long descriptive names will make less chance of me giving the same abbreviations with more than one meaning.

Thanks and sorry for not replying for so long.
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 23rd Aug 2013 21:32 Edited at: 23rd Aug 2013 21:37
Quote: "The Variable Names

The personal reason why I have them so long is because they are the first thing which jumps in my head so when I forget the name (which I definitely do) I can find it quickly by using the search for word feature built in and just find it in seconds instead of having to actually remember it. I also have them over the top descriptive for when I'm not overly awake I can just read it and know exactly what it does instead of trying to figure out what the abbreviation is. This is just what I prefer to use for some strange reason. "

I can understand that for now, but I think once you start coding in a more organised structure it will make sense to cut down the names, and you will find them easier to read/write. If you are struggling to work out what a variable name means, even a heavily abbreviated one, then it is probably a sign that you are mixing procedures together and creating a big blob of code, instead of neat functions/routines that perform a single task.

Quote: "The Menus

I also like to say the amount of features I'm planning to have in this game will involve a lot of menu's and sub menu's which means that having long descriptive names will make less chance of me giving the same abbreviations with more than one meaning."

If you need to change the names I've chosen, they should all be searchable so you can search/replace them.

That's another tip, make sure your variables are searchable; this doesn't seem to be an issue for you, but it's still worth mentioning. If you call a variable, "x", for example, what do you do when you want to change the name? Searching for "x" is no good. Using whitespace can make it a little easier, e.g. "b = x +1", because you can include the whitespace characters in the search, " x ", but you only need one case where you forgot the whitespace to mess it up, and who knows where that residual "x" will be? So it's best to use names that are unique to any part of any keyword. Having a name like "tex", maybe for a texture number, when searched is obviously going to bring along all instances of "text" with it. It's also a good idea to avoid using whole single words, like "name", to avoid finding that word in comments and string literals. Of course, you are not going to need to change/search all your variable names, so this is not essential coding practice, but it will make your life easier if your code is likely to change dramatically.



Formerly OBese87.
Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 24th Aug 2013 16:13
Ah okay that seems to make sense, I will keep that in mind for the future!

I would also really like to know what is causing the issue with the problem I am having because I can't see any reason for it.

'load image Tybalt,4,0,0' and happens on Line 275.

Any help would help
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 24th Aug 2013 16:53 Edited at: 24th Aug 2013 16:59
It might be a good time to think about planning the menu system; modifying text outside the source code.

It would be reasonable to do something like this:



And that was quite long by my standards, but it illustrates where you should be headed; arrays; and also illustrates modular code design; - Separating procedures into reusable parts.

* The use generalized functions permit reuse elsewhere
* The use of smaller modular functions instead of long ones permits flexible adaptation
* The use of variables instead of literals permits the given operation using any variable, on any variable

Here is a small illustration of how my text is extracted from XML and updated in my game; it is way more simplified than the real thing which uses vectors and function pointers, but is practically identical in design:



Count every TEXT command in your program and compare that to these three lines, and think about it:

Quote: "For i = 1 to Array Count( Texts() )
Text Texts(i).X, Texts(i).Y, Texts(i).Content$
Next i"


And think about the X, Y and Content being sourced from where ever you need, not just on the same line of code; be it over a network or from disk. The X position of a sprite, the Y scale of an object, the string being typed on the keyboard; anything.

Another one of my procedures uses INI files:



These contain a lookup to an INI file, a constraint to make sure the values are kept in range, and default value for when the database is missing the value.

Now 'database' lookups should be stored in an array to keep in memory, you would not access the database on every loop of the simulation.

It is a case of deciding for yourself, whether you prefer INI files, XML files or your own file format; you can later on compile such files into blocks of encrypted content.

This is all just a window shop for what kind of procedure you might find desirable.

Quote: "I've been getting another error which I don't understand why it appears which is this 'load image Tybalt,4,0,0' and happens on Line 275."


What is the error message? Is the Tybalt parameter a string containing a valid image file name? (The last two parameters are not required, the texture and divide modes are zero by default)

Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 25th Aug 2013 01:21
Hi Chris, The main thing I don't understand is where does it get the coordinates from?

The problem happens at this set of commands



This part of code is all new to me so I haven't got a clue
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 25th Aug 2013 02:17 Edited at: 25th Aug 2013 18:47
What does the error message say? Could not load image? Or the file path was missing?

Are the images in the file path: Night Watch/Main Menu/ ?

I do not like using Data statements, so you might know more about them than I do.... Since there are other data statements in the program established in chronological order; do you not need to use the Restore command and a label to retrieve the correct data?

You would be better off with arrays really.

Quote: "I don't understand is where does it get the coordinates from?"

Where ever you want to write them; as is the case with the text. In an XML file, INI file, Microsoft Office spreadsheet, HTML, MySQL database, where ever.

You do not even write coordinates, you could draw them in Visual Studio Express and export the layouts to XML or INI files; but that is not necessary at the moment; for now just try and see for yourself.

Here is one example

Create a blank project.

Install Matrix1 utilities; it requires a manual insertion into your TGC folder. If you have Styx, you will need to cut the StyxCore DLL out of the plugins folder, and put it elsewhere. Its core library commands conflict with Matrix1 core library commands.

Write your first INI file

Write the following into a file; call it MyText.ini


That will do for now.

Now all you do is run the following code; this is untested written directly into my browser.



Done! Once you compile it you can display text, edit it outside the program and even add new text to the game without troubling the source code.

I left a few Easter-Eggs in there revealing what tricks I will show you in future once you grasp this part. Look at it word for word, then it should make sense why it is going to make your life more easier.

Although, this is not intended for long term use; just use it as a more reasonable method for defining your text for the time being. Later you will want to avoid having to write indexes manually, and may need to create string formatting functions to dynamically supply game attributes for your text.

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 25th Aug 2013 03:18
Quote: "'load image Tybalt,4,0,0' and happens on Line 275."

I don't know what the 4,0,0 is about, but I know what is causing the error and I have fixed the issue (I thought I had updated the code but no). I will post the fix when you have worked out what is causing the issue.

Quote: "The problem happens at this set of commands"



Yes it does, now what is strange about the error? Where has this "Tybalt" come from? Seems like a very strange word to pop up here out of nowhere.
What is the contents of this imgpath$, that the program is trying to load an image with? If you have no clue, look up the READ and DATA commands.

This error is one example of why it is better to use external files to load data, rather than hard-coded into the program via data statements.



Formerly OBese87.
Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 25th Aug 2013 03:29
@ Chris

Okay I will have a look in the morning as I'm close to falling to sleep at the moment.


@ Libervurto

I think I got a idea of where it may of came from but I will have a better look after I have had some sleep
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Aug 2013 10:46
[MOD EDIT] changed subject to reflect the content of this thread, which is very useful

Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 25th Aug 2013 14:23
Hi Chris,

There seem to be a error in this part of the code you provided to show how to load text in.



It's says in the debug part this, 'Subscript must be Integer or DWORD when referencing an array at line 18.' I haven't got a single idea of how to fix that as I've never done this before


Hi Libervurto,


Right I figured out where it getting Tybalt from, the name section! Now I got an Idea that it is something to do with 'dim' but I'm not sure, but I will keep trying
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 25th Aug 2013 15:10 Edited at: 25th Aug 2013 15:15
Any function that shows up without highlighting is a command unrecognized.

You need to
Quote: "
Install Matrix1 utilities; it requires a manual insertion into your TGC folder. If you have Styx, you will need to cut the StyxCore DLL out of the plugins folder, and put it elsewhere. Its core library commands conflict with Matrix1 core library commands."


Most likely before creating the project I should have mentioned.

Download Matrix1 from here

There are many important commands it will need to add to your DarkBASIC command-set, some of which have already been used in that snippet.

Also...

I forgot to give the GameText variable a value, set it to one. GameText = 1, before the very first line of the snippet; make it global.


Quote: "Right I figured out where it getting Tybalt from, the name section! Now I got an Idea that it is something to do with 'dim' but I'm not sure, but I will keep trying"


You should still let us know what the exact error message says.

Quote: "changed subject to reflect the content of this thread, which is very useful "


That's good!

Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 25th Aug 2013 15:19 Edited at: 25th Aug 2013 15:38
Okay cool I'll just try that in a second.

This is the full error message 'Runtime Error 506 - Could not load image at line 276.
CWD:C:\Program Files (x86)\The Game Creators\Dark Basic Professional Online\Projects\ScrollsOfEithador\Game\Media\Night Watch\Main Menu
LOAD IMAGE Tybalt,4,0,0'


this is the code around that bit




Edit:

Okay Chris I have now tried it and it looks very useful but I'm wondering how it would work with different resolutions, would I need to put different coordinates in the file?


Thanks!
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 25th Aug 2013 16:07 Edited at: 25th Aug 2013 16:09
Quote: "Runtime Error 506 - Could not load image at line 276"


That clears that up then. If the file did not exist, it would not have given you that particular error message; if any... Are you sure all of those images are valid bitmap files? Do they open in an image editor correctly? Can you load them directly in a test project?

If you still do not get it sorted, unless Libervurto wants to help you rectify that issue, I do not think it is worth fixing;

There is no point anymore because all of that DATA/READ poop is going to become history in a short while, so why fix a pile of junk that is to be thrown into the furnace I say.

Quote: "
Okay Chris I have now tried it and it looks very useful but I'm wondering how it would work with different resolutions, would I need to put different coordinates in the file? "


Nope. There will be no such thing as defining any coordinate more than once. Nothing will need to be defined more than once, like a entry in a dictionary, once it is defined, it is defined.

I will introduce you to relativity and ratios next, so that what ever coordinate you supply will be similar on various screen resolutions.

Before we get into that,

1. Do you know how the above snippet got the text to display?
2. Did you manage to create new text?
3. Do you know what most of the INI file content represents?
4. Do you know how to search for a text entry?
5. Do you know why I got away without defining a name for the 'quit' text field?
6. Did you try to play around with different parameters with the UpdateText function call to see what happens?

If you answer no to any of the questions, let me know so if you need clarification.

Otherwise, you should be able to take it from there; and we can commence to the next phase, setting coordinates for any screen resolution.

Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 25th Aug 2013 17:00
Questions:


1. Do you know how the above snippet got the text to display?

I think so, is it this code after you have open it and set it up?


2. Did you manage to create new text?

Yes

3. Do you know what most of the INI file content represents?

Yes the top section is kinda like a goto showing that these things exist inside the file, the bit in these brackets '[', ']' is the title for that bit.
The text part is what is displayed, x and y is the coordinates of where it is displayed and the page is a variable you could load to allow you to have that bit loaded if a certain criteria is met or something of the nature. Please tell me if I have misunderstood these.

4. Do you know how to search for a text entry?

I haven't searched for a file before but I would love to learn how to

5. Do you know why I got away without defining a name for the 'quit' text field?

No

6. Did you try to play around with different parameters with the UpdateText function call to see what happens?

No, I don't really know how to use functions
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 25th Aug 2013 17:10
Quote: "Right I figured out where it getting Tybalt from, the name section!"

Yes, go on...

Quote: "Now I got an Idea that it is something to do with 'dim' but I'm not sure, but I will keep trying"

Nope! Nothing to do with dim, the issue is with an image, not an array.

The issue is a really annoying one. DATA statements are treated as if they are in a big block, ignoring all the other instructions in-between. When you read data, the program reads from the next DATA statement in the list, it doesn't matter what comes between.
Now, I made two subroutines, "_init_recruits" and "_load_images", in that order, and they both contain DATA. However, I called them the other way around: "_load_images" first, then "_init_recruits", so when the program went to read in data for the image paths it started reading the recruit names instead because that was the first data in the file.

This can be solved by restoring (moving) the data cursor to a specified label, which is what I did to fix the error:




Formerly OBese87.
Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 25th Aug 2013 17:33
Questions:


1. Do you know how the above snippet got the text to display?

I think so, is it this code after you have open it and set it up?


2. Did you manage to create new text?

Yes

3. Do you know what most of the INI file content represents?

Yes the top section is kinda like a goto showing that these things exist inside the file, the bit in these brackets '[', ']' is the title for that bit.
The text part is what is displayed, x and y is the coordinates of where it is displayed and the page is a variable you could load to allow you to have that bit loaded if a certain criteria is met or something of the nature. Please tell me if I have misunderstood these.

4. Do you know how to search for a text entry?

I haven't searched for a file before but I would love to learn how to

5. Do you know why I got away without defining a name for the 'quit' text field?

No

6. Did you try to play around with different parameters with the UpdateText function call to see what happens?

No, I don't really know how to use functions



Hi Libervurto,

I have tried to use the code you have done but It got another error now

It's to do with this line 'if leftClick and mouseInRegion(70,90,91,112) then NWMenuView = 0' and it says it this in the debug log, 'User function 'mouseInRegion' must return a value if used in an expression at line 85.' I would try to fix it but I have never used functions before so I haven't got a clue where to start.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 25th Aug 2013 18:37 Edited at: 25th Aug 2013 18:50
Quote: "1: Do you know how the above snippet got the text to display?

I think so, is it this code after you have open it and set it up?"


x = IntVal( Lookup$( GameText, index$ + "/X", "0" ) )


Right. So the Lookup$ function requests the following parameters:

a) Lookup ID
b) Key name
c) Default value (What is returned if the value is unavailable

So, to lookup:

[Character]
Name=Tybalt

It is Lookup$( Lookup ID, "Character/Name", "" ).

x = IntVal( Lookup$( GameText, index$ + "/X", "0" ) )

The IntVal function is a Matrix1 function. It is the same as the Val function, but the difference is that the Val function converts a string to a floating point value, and does not work as well with precision:


Quote: "2: Did you manage to create new text?

Yes"


Then that is almost the end of always having recompiling your program to change add text.

Quote: "3. Do you know what most of the INI file content represents?

Yes the top section is kinda like a goto showing that these things exist inside the file, the bit in these brackets '[', ']' is the title for that bit.
The text part is what is displayed, x and y is the coordinates of where it is displayed and the page is a variable you could load to allow you to have that bit loaded if a certain criteria is met or something of the nature. "


Yes, that is correct. There isn't much difference between fields here and variables in a block of code; just remember; no speech marks are required for strings, and the semi-colon is used for commenting on its own line only, amongst other differences to be illustrated later.

[IniSection]
Key=Value
;Comment must be on its own line


Quote: "4. Do you know how to search for a text entry?

I haven't searched for a file before but I would love to learn how to"


More on file search later.

You use the GetText( Name ) function I created to search for text entries in the file. Looking at its content reveals why we bother to give text names:




Question:

4-R1: The Matrix1 Fast Lower$() function is quite identical to the Lower$() function; just faster. These would change 'ABC' into 'abc', Fast Upper$ would do likewise from 'xyz' to 'XYZ'. - Why do you think this was performed when comparing the names?

(A code alteration was made)

Quote: "5. Do you know why I got away without defining a name for the 'quit' text field?

No"


Because of the default parameter in the Lookup field; we set it to the value of the index$ variable; which happened to also be 'quit'. This is what the name became when the INI field was missing.

The name INI field is optional for post-release changes; the stuff that gets sent with patches to correct mistakes or tackle issues.

Additionally you might get name conflicts, or you might want to display the name as a label with spacing or interesting formatting.

Or perhaps the name might need to have a change of language.

Quote: "6. Did you try to play around with different parameters with the UpdateText function call to see what happens?

No, I don't really know how to use functions"


Well the UpdateText(0,0) is pretty vague for now; but change the zeros to 300 and see what happens to where the text is displayed.

6-R1: Why did this change of text position occur like that?

-----------

To proceed, you will need to let us know if you want more elaboration on this current topic of INI lookups and text management; otherwise there are a few topics you seem to want to improve on; pick one of the following topics for the next phase:

A: More on Lookup files
B: How to use Functions
C: How to search for files
D: How to use coordinates on any resolution

Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 25th Aug 2013 23:52
Well that's good to hear, the main thing I would love to learn next is How to use coordinates on any resolution as that will allow me to complete some of my game menus
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 26th Aug 2013 01:31 Edited at: 27th Aug 2013 01:40
OK, so assuming you know what a UpdateText(300,300) call would do to the text, that illustrates how coordinates can relate to each other.

Make sure you understand how it worked, it is related to what comes next.

Correction The Advanced 2D plugin will speed up drawing commands and improve the look of text; download and install the Advanced 2D plugin (And the help files). More on A2D later.

Now. We will look at using relative coordinates; and we will look at using the screen size for scale.

1
Notice anything interesting about this snippet:



Besides the strange dish, the text was placed in the middle of the screen, no matter what size it is.

Try changing the resolution; this will not affect the central position of the text.

Did you see any difference in the way the two coordinates where calculated. One uses multiplication, and the other uses division; yet their result is the same.

0.5 * 10 = 10 / 2 = 5

So anything multiplied by 0.5, is halved.

If that is true, then what'd be the opposite?

10 / 0.5 = 2 * 10 = 20

So anything divided by 0.5, is doubled.

2
So how do you put text in of the left part of the screen?

If the centre is obtained by multiplying the size by 0.5; then the centre of that part is its size multiplied by 0.5.



There is an easier way to position the text where it was in the last example; but I will not show you. You show me. And I'll give you a hint, half of 0.5 multiplied by the screen width is equal to a quarter of the screen width.

3
Putting text in the middle of a rectangle:

So if you know how to put text in the centre of the screen; and the screen is a rectangular shape; then how would you put the text in a rectangle on the centre of the bottom right hand side of the screen?

Well let us put a rectangle in the bottom right hand side first. We must first figure out where that is;



There it is, so let us make that the centre of a box, which happens to need to be 400x200 pixels.

Where is the centre of 400? 200

Where is the centre of 200? 100

Where is the centre of the bottom right hand side of the screen on the X Axis? Screen Width() * .75 (You can omit the zero in DBP if you wanted)

Which is also:

Screen Width() - (Screen Width() * 0.25)

So if the centre of the rectangle, must also be the centre of that part of the screen, we need to start drawing from there; and here is how:



Now the box is drawn where we want it, no matter the screen resolution; now we simply draw the text inside of it.



So, this gives you a clue as to where we are going with the user interface. But there is a problem with the last solution; what if the box was too large for the screen? Change the resolution to 640x320 and see for yourself.

Now suppose you defined that rectangle as a UI panel; how could you limit its size to the extent of the screen?

This is where Matrix1 comes in for us here. We can use the MIN and MAX functions. The following solution demonstrates this.



Now the Max function will return the largest number in its parameters.

Print Max(10, 20) ` Outputs 20

The Min function returns the smallest

Print Max(10, 20) ` Outputs 10

X1 = Max( X1, 5 )

This maximizer returns nothing less than 5 pixels from the edge of the screen; the left hand side

X2 = Min( X1, Screen Width() - 5 )

This minimizer returns nothing more than 5 pixels from the edge of the screen; the right hand side

4
Word Wrapping in the rectangle.

Most RPG conversation or story text will feature paragraphs of it. So how do we draw paragraphs of text. This is where Advanced 2D comes in for us here. The following demo demonstrates me adding this very paragraph in that rectangle, this time in the top left of the screen.



Here instead of plunking one big fat line of text exceeding the size of the screen; or guessing where the next line-feed should go when writing the text. Advanced 2D has reduced the width of the text block to our rectangle, for us. We have used 5 pixels of margin depth by adding 5 and subtracting 5 from the edge.

We had to create a font and a colour. The font need only be created once, and the each text block can be given its own colour.

Here is another example, this time with the box on the top right hand side, not centralized; with some fancy easter eggs to reflect on



Now you know how to put stuff relative to the screen size; next you can ask any questions about anything you are not sure about. Otherwise, it is time to implement this in your text system. Let me know if you are ready to do that.

We can also discuss increasing the size of your panels to fit larger screen resolutions than are available on your computer monitor.

Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 27th Aug 2013 00:10
Sorry I've haven't replyed earlier just been wrapping my head around some for stuff I've been trying to learn, AI to be precise, anyway so this is the code for getting it in the center quicker and lest calculation




Okay this is really good but I have came across a issue with it. The commands from the new plugin have caused a major drop in frame rate on one of the parts of my game, this is the only bit I tried, but it caused it to drop by about 40 fps from these commands for some reason (just the text, with everything else pre done, e.g. no calculations for coords etc, as I messed around with it late last night to see if I could get the hang of the plugin before reading the rest.)


Another thing which will be of great use to me is doing the same thing but with sprites, so making them take up the same amount of room depending on the resolution. What size should the actual picture be so it looks good on every screen etc.

All this I'm understanding fine and thank you for taking your time to help me through it
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 27th Aug 2013 00:57 Edited at: 27th Aug 2013 01:14
Quote: " The commands from the new plugin have caused a major drop in frame rate"


Impossible... That's like saying a slug beat an ostrich in a race across a field. Note that the new commands start with a2, the snippet you posted is still uses the old commands. Advanced 2D can never be slower than the old commands, I have even used it to draw the entire scenes multiple times per frame.

If you are jumping ahead a little, when making use of its line and dot commands in multiple iterations; make sure you use the batch commands; see the documentation. (Do not lock the pixels for A2D usage)

Another thing to note, is that the calculations should be done as you load the text, not on every frame; there would be no need to do that. After you have calculated the coordinates, store them in the designated UDT fields.

As for sprites, you do the same thing. You position them as you do the text. Remember that halving the size of the sprites can be achieved by Scaling them at 50%, or multiplying their scale by 0.5.

Let's say your monitor was running at 800 x 600, and my monitor was running with 1600 x 1200 pixels, how do you make the sprites the same physical size? Let's imagine that 72 pixels represents 1 inch.

If 72 pixels, that's one inch; was the required size on a 800 x 600 screen; then what size would it need to be on a 1600 x 1200 screen? Do you see a pattern with those particular resolutions; 1600 pixels is twice as much 1200 pixels, and 600 pixels is half of 1200 pixels;

therefore the size of the sprite needs to be halved on my machine.

But let's say you did not know my resolution, what then? You divide your reference resolution, by mine. 800 / 1600 is 0.5, which is what you multiply your sprite scale by.

Post up any code you need a hand with as always.

Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 27th Aug 2013 01:13 Edited at: 27th Aug 2013 01:15
I know this seems impossible but I'm not lying for some reason it seems to be this way round, so confused.



Default:

[img][/img]






With New commands

[img[/img]


Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 27th Aug 2013 01:35 Edited at: 27th Aug 2013 02:12
No you were right; I got two things mixed up; it is the 2D drawing commands that are faster; not the text command. The text command's advantage is the word-wrap and anti-aliasing (smoothing).

Should be best to use normal pixel text for small text, and smooth a2D text for large rounded fonts. a2BoxText is good for paragraphs as we saw.

Drawing tests:







Image pasting test (More or less the same speed, but you can change the colour, opacity, angle and scale of the image with a2d:





What is Advance Sprites doing for your game?

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 27th Aug 2013 02:07
An after thought leads me to become confused aswell now. Why would 8 calls to the advanced text command drop the framerate from 50 FPS to 11 FPS

Something is not right; I wonder if there is a conflict with the Advanced Sprite plugin. I have loads of a2Text calls in Sports-Fiction at 60 FPS, you have only 8 calls and yet only 11 FPS.

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 27th Aug 2013 12:40 Edited at: 27th Aug 2013 12:47
I don't know if this would cause that much lag but it certainly doesn't help to have all these RGB() calls.


Colour values in DB are made up of four components: Blue, Green, Red and Alpha Transparency. I write them in this order because colour values are little-endian (smallest bit first), we are used to writing numbers in big-endian form so we say, "RGB", not, "BGR", (although we should say "ARGB"/"BGRA").
In binary, the structure of a colour value is intuitive, it's simply a list of all four ARGB components one after the other, but when converted to decimal these numbers are not so intuitive. This is why we have the RGB() function: it takes RGB component values and shifts their bits so that they stack on top of each other without interfering.
Each component of RGB/ARGB can have a value between 0 and 255, a total of 256 possible values. 256 = 2^8 = 8 bits = 1 byte, so to stack the components beside each other we need to shift them in increments of 1 byte. We already know that 1 byte = 256, so we also know that shifting up by one byte is the same as multiplying by 256.
Therefore: rgb(r,g,b) = b + g*256 + r*256*256
E.G. rgb(255,255,255) = 16777215

Every time you call the RGB() function you are adding those calculations to the program, so it's much better to use RGB() once at the start of the program and store the resulting colour value in a variable:




Formerly OBese87.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 27th Aug 2013 14:04 Edited at: 27th Aug 2013 14:07
Good points, that is all good information.

But even so, a 40 FPS drop is 25 milliseconds; there is no way 8 RGB functions or a2 text commands should take a 40th of a second to compute.

I use a loads of RGB calls for interpolated colour animation and text extrusion effects with no such drop in framerate.

I can understand a 0.5 millisecond (500 microsecond) or a 1 millisecond drop with that code block; but not 25.

Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 27th Aug 2013 14:20
Hi, okay I will use the normal commands instead of the new ones except when I need to wrap text etc.


The reason why I thought I needed advance sprite is because I thought it would improve the fps of my game as I use a lot of sprites.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 27th Aug 2013 14:45 Edited at: 27th Aug 2013 14:50
You should still find out the cause of the problem; you might find using a2D image pasting will be useful in certain situations later on, and not to mention large standard text commands look pixelated.

If you do not know what causes the problem even the word wrap calls might slow things down.

For example, here is something identical to your a2 Text code, in addition to the RGB call, there are 8 RND calls.

I am getting 1200 FPS!!!

Could you run this test with some calls to Advanced Sprite commands in it, and then without Advanced Sprites. Just to see if there is a conflict with them.

You should trust me, there are some situations where a2D will help make the UI development easier; need to know what's going on so that it is clear whether or not advanced sprites has a conflict with it; A-Sprites looks like a nice command-set, but it will be pointless showing you a2D UI tricks if you can't use them together..





Another thing is text transparency; Matrix1's RGB function can have four parameters: RGB( A, R, G, B ); use that to change the colour and opacity of the text:

a2Text MyFont, Rnd(500)+200, Rnd(500)+200, "ABCDEFGHI", Rgb(128, 255,255,255)

and also the colour and transparency of images:

a2DrawImage img, x, y, CentreX, CentreY, Angle, Scale (usually 1.0), option (0), RGB(128,255,0,0) - makes the image semi-transparent red.

Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 28th Aug 2013 12:37 Edited at: 28th Aug 2013 12:43
Okay I have done some tests and it seemed not to be what we thought it was so I think Libervurto may have a point about the rgb calls.

This is with the default dbpro sprite commands

[img]
[/img]



This is with advance sprites

[img]

[/img]




Okay I found out that if you use the rgb command instead of a integer to represent the rgb it dose improve the fps but also lowers it because it jumps from being 10 fps more than before to 10 fps less meaning it isn't the most stable but could also be better in a way, I'm not entirely sure what is causing it, could it be Dark AI as I use that in the application which had the massive drop in fps?
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 28th Aug 2013 21:15 Edited at: 28th Aug 2013 21:26
I think it might be the version of DBPRO. You are not the only one who is experiencing the problem; so be it. At least you have options.

I agree with the point of using RGB to store a value, but I do not think it is the cause of the slow down; a 10 FPS loop is just atrocious. It is the 21st century, most PCs have dual core processers.

No RGB call should hijack so much FPS like that, something is up with your setup, or the test you performed.


1000 RGB calls, result:


1600 FPS!


If I am wrong about RGB calls not being the culprit, then I do not know how I am going to get away with creating my world editor's particle effect timeline editor, interpolating all those colours with RGB properties.



FPS is not a very good measurement of performance anyway. For example, 10 FPS is a 100 millisecond loop. 20 FPS is a 50 millisecond loop. 50 FPS is a 20 millisecond loop. 500 FPS is a 2 millisecond loop.

So losing 10 FPS from 10 FPS is way more severe than losing 10 FPS from 100 FPS.

It is harsh for 8 minor RGB calls to ruin your game like that, something is wrong. I've got at least 30 RGB calls animating colour transitions in one of my UI components I am developing for SF.

Just something useful to know:
White = 0xFFFFFFFF
Black = 0x00000000

These two colours are the same:
White = 0xFFFFFF
Black = 0x000000

Except the first two hexadecimal digitals which represent the alpha channel are omitted; not good for any a2D command, but fine for standard commands.



One of the first things I put in my engine was a benchmark system. It times all the parts of the engine and tells me what is slowing things down; slow downs no longer concern me; I know where the bottle necks are and what is causing them.



This is why I might seem a bit assertive, bold and concerned about your engine performance, what is slowing you down is not what is slowing me down, usually.


How is the AI going.

Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 28th Aug 2013 21:29
Right I ran exactly the same test as you did and I got 1000 fps and that was as my laptop was trying to recover from me crashing about 5 times in a row from trying to load a 4mb file to texture a world with. So should get higher in the future.

The AI is going very well at the moment, I got Follow(group up around the player), Column(follow in a line from behind) and Line(shoulder to shoulder kinda thing) working well at the moment, it works on any axis and angle plus they stay on top of the ground which is always good I just need to figure out how to make it so another line will line up behind the first one which I'm finding a bit tricky as you can't just add to the z axis for example which is just a pain but I will work it out


I also been doing a lot of terrain making which is going quite well just having the issue of doing paths on it, tried to put it on the texture but that doesn't work at all. Any ideas?
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 28th Aug 2013 22:22
Cool.

Use the terrain height-map as a reference; since that is the reference for the terrain. Use the pixels to constrain where the paths can go. You can use dummy objects to affect the AI waypoint generator.

Ask Kaedroho for tips if you are using his Blitz Terrain plugin.

Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 28th Aug 2013 22:56
Yea I have been using the terrain built in height feature and I have just posted on there so hopefully I can find out
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 11th Sep 2013 14:49
Quiet lately? Back at school? How did the AI waypoint effort go?

Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 12th Sep 2013 05:24
Quote: "One of the first things I put in my engine was a benchmark system. It times all the parts of the engine and tells me what is slowing things down; slow downs no longer concern me; I know where the bottle necks are and what is causing them."

This is an excellent thing to do, bravo.

Your slowdown may have something to do with a draw mode or bit locking sort of issue being done each call. I know the D3D text plugin is like this where it makes you enable a draw mode then do all of your draw commands and then disable the draw mode. It's been a while since I looked into this and I'm on my mobile.

I had a similar problem using the built-in 2D commands. Some of the replies should help you. Here is the thread I posted:
http://forum.thegamecreators.com/?m=forum_view&t=195887&b=1

Flamertor
14
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 14th Oct 2013 19:25
Hi, yea sorry I've been very quite, just started college and it's in the middle of the fencing season! I've haven't done a bit of programming for quite a while and didn't see your comments. I'll have a look at it soon!

Login to post a reply

Server time is: 2026-07-06 18:42:43
Your offset time is: 2026-07-06 18:42:43