.:: Alex Erne :: PHP/MySQL & Unity3D/C# projects ::.
Recent news
Categories
Like me on Facebook
* advertisement *
  04 June 2016 - Languages fully implemented :: Posted in d20 project

After having created all code for the talents, I figured that with the Smart Hero's Linguest skill I might as well work on the language implementation first, and as written earlier this week, I decided that languages would get their own class because of a fundamental difference with them in d20 Modern compared to d20 Fantasy (Dungeons & Dragons 3.5).

Entering the code for about the 50 languages named in the d20 Modern system was easy enough after I figured out how to get this working. Coding the use of the languages in the demo I'm making was a bit harder though. While coding the demo I also found out that there were certain calls to the main d20project plugin that I still had to make.

 photo d20project 20160604_zpsyjqvji2k.png

One of the most challenging issues at hand was the use of a prefab that uses 2 dropdown UI menu items. While it might look easy from the user's poitn of view, the Unity engine has a terrible flaw here that resets the 'Label' object to that name back again when you've made it a prefab. And while not overly important, the 'Label' field is used to show the 1st entry of the options list when the prefab is loaded.
The easy way around this would be by making 2 small pieces of code that would control the 2 different dropdown UI menu items, but that would kinda screw the interaction with the 2 toggle UI items and 2 UI buttons I also have in this prefab. So instead I've had to be very creative to work around this issue and as you can see (in the above picture) I managed to get it working.

An other technical issue I bumped into was that the dropdown UI menu options are converted to the string type, while the languages values are stored in an enum type. Though this might not sound too significant, it did give me a lot of problems when coding the OK button, where the language selected would be added. Unlike when adding an option from a single menu dropdown, where you can simply point to the field in the list with [dropdownmenu.value], using 2 dropdown menus where one selection (language groups) changes the list of the other (languages itself), this direct approach is not available. Instead I had to compare the string type of the current selected language with one the values in the enum type. And eventhough C# is very flexible with casting one value to an other, it is impossible to cast a string type to an enum type As a final option I had to write an extension class that's much like the ToString() one to convert the string holding the selected language into an enum type from the language list.

Now "all there's left" to code for the d20 project is the implementation of adding talents for the basic hero classes, of which I have already done most of the work and a simple popup like the one used for languages is required to get it working (and test the code immediately). After that (when my test character hits an even level) add the (bonus) feats in a similar way, including the special feats (not actual feats, but pretty much like them) for the advanced hero classes. When those 2 are coded, a couple of small tihngs need to be fixed/coded in the usage of the core rules, like reputation, action points and wealth. After that only the 'big thing' to implement is of the hero's gear and equiment of it remains, which will still need some work I fear...


Post A Comment! :: Permanent Link
  31 May 2016 - Languages their own Class() instead of Skill :: Posted in d20 project

While adding the talents earlier this week and being stuck on the prerequisits of the Smart Hero's Linguist talent (Research talent tree), I found out I was making an error on languages in d20 Modern.

I've been used to d20 (Fantasy, or rather (Advanced) Dungeons & Dragons), where the Speak Language skill can be obtained a couple of times, each time for a new language. When obtaining Speak Language you could automatically read/write it *caugh* impossible in illiterated medieval fantasy settings *caugh*. In d20 Modern however, the Speak Language and Read/Write Language skills are two different things, meaning you can read one language but not speak it and vice versa.

Though it might be odd that these 2 skills have been created as seperate ones, it does make sense when you think about it. We (Germanic language based) will have a lot of trouble to speak a language like Japanese and to read/write it. The difference between verbal and written language is HUGE in some cases. And while on the subject, d20 Modern also through it would be handy to group languages by their origin as well. And these groups influence the DC of the Linguist talent tests. When the unknown language is within your language group, you have a DC15 to understand the (general) meaning of the message, if it's an other group the DC will be 20 and for ancient/unique languages you'll have DC25.

In C# code that'd mean that I should use both Speak Language and Read/Write Language and keep track on what languages the character knows and in an odd way link that language to the group. And I've made odd way bold on purpose because it will not be clear for the user of the plugin (yes, I'm still serious on releaseing it to the Unity Asset store) how this is handled.

Instead I will use the Speak Language and Read/Write Language skills only to keep track of how many foreign languages the character knows. In addition to this I'll add classes that'll hold the properties of each language, including what group it belongs to. Then (like with skills), I'll add a new List<> to the main character data that'll hold the language and if the character knows it as speaking and/or read/write.

I realize this is a lot of extra work (and that data flowshart I showed earlier is already big), but it'll make things a lot easier when using the d20 Modern plugin, and that's the main thing I should keep in mind...


Post A Comment! :: Permanent Link
  28 May 2016 - Talent trees added :: Posted in d20 project

I haven't worked on the d20 project for about a month, but that was because I was busy with experimenting on other things the last month. But yesterday I've picked it up again and took a look at how the character creation is working. And speaking about character creation, I am already busy on making a 'demo' charachter sheet that'll allow you to make a full blown character with the d20 Modern ruleset. Aside from it being kinda required to show how the d20 project works when I release it as a Unity3D plugin to the Unity Assetstore, I also need this character creation to see how my progress is coming along and have a visual view of things.

Playing a bit with the character creation, I managed to make a character where I could add skills, levels and new classes and I figured to start on the next part, adding feats to the character. But when I took a look at the rules I noticed that a level 1 character first obtains a talent (a character with a basic class gets a talent every odd level, while every even level it'll recieve a bonus feat) and this somewhat forced me into coding the talent trees for the basic classes first...

It's a good thing that only the basic heo classes have talents. And though the advanced classes have something else that's special every couple of levels, their 'specials' are more like feats than like talents. With that knowledge I started on the talent tree coding yesterday in it's basic form. But I wasn't overly sure if that basic form was good enough to be used when adding talents, because most talents in the tree have a basic requirement of an other talent in that or an other talent tree, and that's the major difference between talents and feats.

 photo d20SRD_Modern_zps9joche4r.png

After having had a good night's sleep (or lack there of because I still sleep only 3-4.5 hours a night), I had enough time to rethink the way I coded the talent trees and came up with some small changes (which I've already implemented) to end up with the above flowchart (talents can be found center right). With the data usage of talents now being as I want (and need) them to be it's time to code the functions that'll use them so that I can add them to a character as the rules meant them to be used.

This also is a time to reflect on the size of the d20 project as a whole and is the reason I've included the whole (current) data flowchart. As you can see, I'm shuffling a lot of data to and forth the d20Character class (which holds the actual character sheet) and at times I loose track of what data goes where and need a close examination of the flowchart (that's also the time might I put the project aside and play a game on my PlayStation 3 ).
Also worth to note is that the actual written code for the d20 project is begging quite big as well (which you probably figured looking at the flowchart ). The main code already consists of 13 files with a total of close to 300Kb, while de visual demo I'm working on only is around 120Kb. Worth to note is that the daily back ups (in compressed RAR format) I make (these also include all data Unity generates) have grown from a bit under 700Kb at start to close to 2.2Mb yesterday...


Post A Comment! :: Permanent Link
  24 May 2016 - PHP.net's 8-year old stripslashes() bug :: Posted in General

Today while working on the MySQL connection tests with Unity3D I identified a bug in PHP. This bug concerns the stripslashes() function. This function should be used in conjunction with addslashes(), which add escape codes to ', ", \ and null while stripslashes() SHOULD remove them again.

Since these 2 functions are not native to MySQL, but PHP, I had to write them for Unity myself. Using an old copy of this blog locally, I have enough data to read and test, while I can edit it as I please on my local server. During these editings I found out that the \ was processed normally using addslashes(). But when I requested the blog entry on the local webserver, the \\ which was stored in the database was compeltely removed instead of returning a single \.

This is clearly a bug, because how else can we store stuff safely in a MySQL database..? And therefor I wanted to make a bugreport about the issue.

Having no account though (after having laid out the whole bug, I was shown similar reports and one caught my eye: https://bugs.php.net/bug.php?id=44876&edit=2. This report dates back to 2008 and describes the same bug I've encountered. But the response from the PHP.net team is just baffling: "This is expected behaviour and has always been this way.". Yeha, the description of the function is clear, but it's not conform it's counterpart addslashes().

Basically, a piece of code like:
        stripslashes(addslashes("\"))
should return '\' (without quoted) and not the empty string '' (without quotes, but hard to display an empty string without them )

Clearly there is no solution for this issue, other than make your own function in PHP to substitute stripslashes(). It's a good thing that I found this one so that I can change the code of the I am Blog project (eventhough I have declared it dead yesterday, but this is a bug I MUST fix).

...all instances of \ were changed manually in the database into &#92; to make this post show up correctly...


Post A Comment! :: Permanent Link
  23 May 2016 - Unity, Linux & MySQL (or the start of a persistent online world) :: Posted in Unity3D

Today I've been experimenting with the MySQL .DLL files, which can be used to allow the Unity engine to connect to a database. Of course, it's not recommended to let a client game connect to a database because of security issues. On the server side of things though it's not a problem, where the clients connect to the server side program, which in turn connects to the MySQL database and submits the results back to the client. This way there's no security risk at all, and (more importantly) will allow to creation of a persistant online world (either small scale multi-player game or even a MMORPG).

I've been thinking about making a persistant online world for a bit longer than the last couple of days (also see yesterday's blogpost). The bookmarks I've made on the use of (remove) MySQL servers are from the time I started working on TetraGems, back in 2013 already. But I never really did something with them because I had no use for a persisntant online world at the time. But ever since I've started on the d20 project, the thought about creating a persistant online world grew stronger and stronger. And with last week's first tests on client-server connections, the next logical step was to see how Unity works with MySQL...

One of the most important plugins for MySQL to use with Unity is not in the asset store, but discussed on the Unity forums. In fact, it's quite an old thread as well! Dispite this thread being so old and the .DLL files that come in the package are as old too, they still DO work with the latest versions of the MySQL databases. The only thing that bugged me of that plugin and documentation was that massive load of useless data it has. Okay, it's an example project where player data is stored, but that's not directly what I wanted to test. I wanted to see HOW it all worked with as few lines as possible. And being a certified PHP/MySQL programmer, it couldn't be that hard to get a simple piece of code going...

 photo Unity MySQL reading_zpst9v6omlk.png

And indeed it's not that hard to get MySQL going with Unity under Windows. I fired up my Wamp Server where I still have the old test database of the I am Blog project (BTW that project is dead now that I'm into Unity ) and I gave it a couple of tries with queries I took from the I am Blog code. First the simple ones and they worked flawlessly. Then a couple with nested queries and those worked very well too! Basically everything I've learned from the PHP/MySQL certification can be used in Unity as well. There is one problem though. Where in PHP you can easily process the code, in Unity distilling the data is less programmer friendly (at first glance I must add - I still have to dive deeper into it) and every query needs it's own.
...while reading this I think I could use a return(myReader) for the MySQLRead() method and process the data somewhere else, allowing me one reading method and different processing methods...

Under Windows it's all working, but what do you expect with .DLL files that originate from the platform..? How about using these .DLL files under the Linux version of Unity..? I copied the project to my Linux machine (which will become the server of my persistant online world) and the Unity editor accepted the code and .DLL files without a problem. The only problem though is(was) the lack of a MySQL server on the Linux machine.
With Wamp server being a Windows Apache/PHP/MySQL server, I was in need of something similar for Linux. I did find a couple of similar packages, but all required me to logon as root on Linux. And being still very much a newbee on Linux I had no clue how to solve that.

When I looked in the Ubuntu Program Manager I found a MySQL working space that'll visualize your databases, which is exactly what I need. I don't need some Apache server package when I only need a MySQL database installed. Of course, the MySQL database server itself is available for Linux as well, and installing those 2 solved my problems. After having meddled with theMySQL working space program and figuring out how everything works, I could import the test database and run the same code under Linux. Aside from a couple of import errors (somehow MySQL imports tables always in LOWERCASE) and chancges to my C# code, the output was the same as I had under Windows.

Now with both being able to use client-server connections AND work with MySQL under Unity, the next challenge comes: figure out what the best coding configuration for the server will be and how stuff is handled there for the clients. I don't want the client to have any checks of the game, but instead it has to get the data from the server...

[NOTE] I will make a full guide/documentation on how to implement MySQL with Unity later on this year (when I've figured out all the things to know of the DLLs included)


Post A Comment! :: Permanent Link
  22 May 2016 - Experimenting with clients & server :: Posted in Unity3D

The last couple of years (ever since I started to play Lineage II back in 2005 actually) it's been a dream of me to make a small-scale MMORPG, but I had no idea on where to start back in the days. That was before I discovered the Unity3D engine. Now that I've gotten used to the Unity3D engine, mastered C# and OOP to some degree it's time to start on that dream...

To get started on the dream, I've made a small client-server script earlier this month and I was able to establish a connection. Sadly though I was not able to send data between the client and server. Digging a bit deeper into the Unity documentation, I discovered that I was using the legacy instruction set that's no longer supported since version 5.1 (Unity is now beta-testing version 5.4).

So I had to dig some deeper into the multi-player components Unity3D supports and it seems that it's actually quite easy in the basics to setup a multi-player game with the new instructions. The guys at Unity have made a very well designed High Level API that takes care of everything you need. It allows regular player-side hosting and matchmaking of games (shooters come to mind) and I  guess that's the main reason for what it's been designed. But with a creative mind you can adept the player-hosting of games into a dedicated server that allows multiple clients to logon. And that's where the MMORPG idea starts to take it's form...

 photo Screenshot 2016-05-18 11.15.35_zps6rfwwnnn.png

In the above screenshot I've been playing a bit with the basic tutorial code and experimented with multiple connections on one PC and as you can see it works pretty nicely. There is one dedicated 'server' there (3rd from the right on the top row) and I have 26 clients connected to it. The communication between the clients and the 'server' goes pretty smooth (duhuh - it's all on one PC ) in performance it's not overly heavy on my old AMD Phemon II 1090T with 16Gb. That would imply that my Linux machine (AMD Phenom II 945 with 8Gb) should be able to host a dedicated server easily...

 photo Capture 20160522 0740_zps4walir97.png

The only problem remaining though is that every screen (inluding the 'server') is showing the same cubes. And while cubes don't take that much performance, imagine a server with 100s of players online having to cope with the full map and each and every textured player. That's mean that my Linux machine won't be able to keep up with performance, and therefor I made an other test.
In the above picture I've changed the 'player' in the Unity editor from a cube to a capsule to see how it'd behave on the server and other client. As you can see, only the Unity editor has it's apperance chanced and it stays a cube on the server and other client. And that's exactly what I wanted to make sure: the apperance is client side only and not broadcasted to the other clients.

With this knowledge I can make players, the game world and monsters/NPCs appear as they should be on the client, while on the server they will consist of only simple things like capsules and untextured structures that all have a collision box. This way I can keep the server running at maximum performance AND keep collision (and other checks) on the server side of the game to avoid cheating.

Of course, this is only the groundworks of my MMORPG. I still have a lot to learn when it comes to modelling and animating 3D objects and figure out how to use a database with Unity3D on the server side. And speaking of groundworks, remember the d20 project I've been busy on the last few months? It's still alive and I'll be using it (in a modified form) for my MMORPG...


Post A Comment! :: Permanent Link
  28 April 2016 - ...or stick with Unity3D..? :: Posted in General

Earlier this month I posted about a possible change to Unreal Engine because the RPG a friend is working on will be build in that engine. Of course, being invited I figured to change to Unreal Engine, but now I'm not so sure anymore. Reason for this change of mind is twofold....

First off, I've recently done my annual tax stuff and looking at it, I saw the monetary investments I've done last year and they are already pretty hefty. Including the investments I've done in 2014 the total is a bit over €900 already (approximately $1000). And while some of that invenstment is on generic tools that I can also use for Unreal Engine (talking about €560 here), a lot of tools I've bought are Unity specific.

The other reason is probably more important to cosider sticking to Unity3D, and that's my knowledge of the engine and the C# programming language. Certainly with the d20 project my knowledge of both is growing exponantionally and I think it's a real waste to hop to a new development environment. With that, Microsoft also has made .NET for Linux and Unity3D is very busy on making a Linux client (running the beta now), while Unreal sticks to Windows and Mac as platforms for it's client.

The only reason to change to Unreal Engine would be to make 'better looking' games. But I doubt that'd be something I really want. I'm an indie developer and I won't be able to make a game looking like a AAA title. I even don't want to make one looking like that, because of all the ranting that'd be done by the players when something isn't like they want (wich is 'extremely normal' by the average spoiled AAA gamer). I'd much rather make something I like and if it looks less like an AAA title but the gameplay is okay, then I'm already happy. And for that Unity3D is a good engine for me to use...


Post A Comment! :: Permanent Link
  Page navigation
  Page 3 of 28 :: Previous Page :: Next Page
* advertisement *
* advertisement *

This website is Copyright © 2009 - 2016 Alex Erné
PHP/MySQL coding by Alex Erné Copyright © 2009 - 2016 Alex Erné
...all rights reserved...

AE games™ and the AE games logo are Trademarks owned by Alex Erné
TetraGems™, Burst-a-Bubble™ and the Burst-a-Bubble logo are Trademarks owned by Alex Erné