Jump to content

Search the Community

Showing results for tags 'programming'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Community
    • Community News
  • Web Game Design and Development
    • News & Updates
    • General Game Development
    • Creative Discussions
    • Coding and Programming
    • Tutorials and Guides
  • Marketplace
    • Looking To Hire
    • Looking For Work / Commissions
    • Marketplace Reviews
  • General Discussions
    • Off Topic
    • Community Feedback / Help
    • Jokes and Fun
    • Entertainment Talk
  • Novilar's
  • Eliyo's
  • Animal Acres's
  • Neopets's
  • IcePets's
  • MisticPets's
  • PokemonPets's
  • Flight Rising's
  • Lioden's
  • Tattered Weave's
  • Furvilla's
  • Eqcetera's
  • Equiverse's

Product Groups

  • Adoptables
    • Eggs
    • Backdrops
    • Additional Customizations
  • Advertising

Adoptable Stages

  • Corgicock
    • Egg
    • Chicgi
    • Corgicock
  • Lizardly Dragon
    • Egg
    • Kimono Lizard
    • Spiketail Dragon
  • Spiky Cat
    • Egg
    • Kittykin
    • Pinat
  • Dwarf Unicorn
    • Egg
    • Filli
    • Unicorn
  • Melon Kangaket
    • Egg
    • Kangakit
    • Kangakoo
    • Kangaket
  • Fuzzy Yeti
    • Egg
    • Yetiling
    • Fuzzy Yeti
  • Pure White Mottled Hare
    • Egg
    • Pure Mottled Kit
    • White Mottled Hare
  • Mottled Hare
    • Egg
    • Mottled Kit
    • Mottled Hare
  • Fawsh
    • Egg
    • Fawsh Younghoof
    • Fawsh Wavestrider
  • Oasis Naga
    • Egg
    • Oasis Nagaling
    • Oasis Naga
  • Kitsu
    • Egg
    • Kitsee
    • Kitsu
  • Vine Sloth
    • Seed
    • Vineling
    • Vine Sloth
  • Worm Cat
    • Egg
    • Wormling
    • Worm Cat
  • Demikin
    • Egg
    • Demonite
    • Demikin
  • Wolbit
    • Egg
    • Wollitte
    • Wolbit

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


About Me


Website


Xbox Gamertag


PlayStation Network


Nintendo ID

Found 12 results

  1. IcePets.com is looking for help. We have been working on some massive changes to the site recently. We are converting the layout from using strings built up in the code to use a proper templating engine (Twig V1). Technical Requirements: PHP 7 Eloquent Models VueJS jQuery (removing most of it - but it's still there) npm/yarn Composer - We use this to bring in the models Twig git You will be working directly with me (developer) and my team to convert not only the layout over to using Twig, but also lots (all) of the database queries from using the mysql_* functions over to use Laravel's Eloquent models. I have done a fair bit of work already setting up the groundwork for it, however, to take it home I may need a bit of support. Applicants - please provide: Resume References Code Samples
  2. Hey guys! I dabble in coding every now and then, never for any sort of profit or commissions...mainly for personal use. The HTML/CSS stuff I've learned has mostly been from messing around with DeviantArt journal skins and I'm fairly good at problem solving with it now. I am starting an ARPG Species on DeviantArt and I'm attempting to do all of the work 100% myself (because I like a good challenge). Are there any coders out there that might be willing to take on a young grasshopper and help me code my own breeding roller? I understand Java enough to be able to read it. I just don't know where exactly to start. Even if I could just have someone help me with the first portion that controls the base coats in the genetics, I SHOULD be able to do the rest with very minimal questions. Alternatively, if someone is bored and just wants to code the whole thing and teach me how to do it as you go, that's fine as well. Basics of what I need: The breeding roller will be a tool for admins of the ARPG to roll the resulting litter of a breeding request from a player. Players will send in a comment with links to the two parents. I will need something that I can enter the genotype and a few other options into (such as if they have a breeding item that changes the chances for something). This breeding roller will need to randomly generate a number of pups between 1 and 8. It will then need to randomly generate genders for the resulting pups. It will then need to give genos for each pup based off of the genos from the parents, as well as a few random mutations and defects that have small chances of popping up in any breeding. I FEEL like this would essentially be a fairly simple project if someone were a master in Java, but I am nowhere near a master and don't even know where to start. It's like I can read the language, but I can't speak it. Lol.
  3. Hey guys, I'm the head artist of a newly developing Deer-based SIM, which has fantasy-related elements to it as well. We're in need of a number of coded things such as registration, breeding/genetics system, currency system, etc For a short term.. honestly, I think if someone had basic codes that we might even be able to buy (starter package? Do people still do those?).. that'd be pretty big for us. For a long term, it would be unpaid (it kills me to say this) until we really have ground work under us (such as crowdfunding or a patreon, site splash set up, etc). Although, back pay for the work done will be paid when cash is available. The pay is something to talk about, whether you'd want cash money, site currency or art for your time. I'm not the creator of this site, but I'm willing to offer my artwork as payment for code. If you're interested, but not into not getting paid right off the bat for custom coding.. please, still reach out. If we have an idea of what sort of money is needed to purchase your time/programming, we'll likely be able to have a better idea of how to make it happen. We primarily use Discord for contact, if you'd like to talk on there my handle is Sunny#2841 Otherwise, please PM/reply here to me. Thanks, Percy
  4. Lots of free programming eBooks available for all sorts of different programming languages on http://books.goalkicker.com/. Here's a few book titles to give you an idea of what they have: .
  5. Update 12/7/2017: This diatribe is intended for developers using frameworks like Laravel, Rails, Symfony, etc. TL;DR See list at end of post for features that probably aren't worth the effort to write yourself Introduction When starting a new project, there's a temptation to write everything yourself, from user registration to forums. Don't. You don't need to reinvent the wheel when there are already hundreds of implementations out there. Every hour you spend developing a common feature is an hour you are not developing the core of your game, e.g. breeding or pet customization; and every line of code you write is another line you need to maintain. When you have a fresh, clean slate in front of you, maintenance doesn't seem like a huge concern, but the time cost quickly adds up. TL;DR Make "Code as little as (reasonably) possible" your driving philosophy "But..." "... I just need a lightweight forum system." The lightest traditional forum system requires at least three database tables (forums, threads, posts) and associated models, each with their own set of validations (threads must have subjects, posts cannot be empty, etc). Then you need authorization guards so only staff can create and delete categories, pin and lock threads, and so on. This might not sound like a lot of work for someone who can spin all that up in four commands (looking at you, Rails devs), but remember that for every feature, that's another thing you need to write tests for and QA. (You are writing tests, right?) TL;DR There's a package for that. "... I need X special feature." Let's say you want to display a user's title on their posts. This isn't a feature that's going to come in a third party forum package, but it's a feature that can easily be added to one. Good third party packages have interfaces or designs that allow you to tweak or hook into their behavior. For that forum package I've convinced you to use, just open up the post view and add in the relevant property. This is (potentially) one line of forum-related code. TL;DR There's not a package for that, but there's a package you can build off of. Choosing the Right Package Caveats Only use popular open source software with a permissive license e.g. MIT, CC0, or Unlicense. Most major open source projects use one of these licenses, or some other flavor of Unlicense. If a package's license is not mentioned in their readme section, there's likely a LICENSE file at the root of the repository. Never trust closed source software that isn't extremely well regarded—and even then, I can't think of any examples beyond maybe plugins for game engines like Unity, which is a different beast entirely. Metrics When choosing a package, there are four qualities I look at first: Features Extensibility Contributors, downloads, and community regard Stability and ongoing maintenance TL;DR You want a package that reasonably fits your use case, is easily extensible or configurable, is highly regarded by your framework's community, has a robust stable release or is actively updated, and doesn't have any major bugs! (Wait, that TL;DR might have been longer than the section...) Regard, Downloads, & Community Standards You don't want to just grab any random package from GitHub's dregs. The number of contributing developers and downloads isn't the end-all metric for package evaluation, but if a package has a dozen contributors and hundreds of thousands of downloads, it's probably good to go. If there's not a package in the top three results when you google "<framework> <feature>" (e.g. "rails forums") and if you can't find half a dozen Medium articles about it (because apparently every dev has one of those now!), then you might be out of luck on that one. Features Let's continue with the forum example and pretend you're using PHP and Laravel for your back-end. Write down bullet points for all the features you need. An example might be Traditional forum structure, e.g. categories > forums > threads > posts Permissions, e.g. only staff can pin or lock threads Admin panel to create/edit/delete categories and forums @mentions Now let's do a quick search for "laravel forum package", and it looks like there are two strong contenders, Laravel Forum and Chatter. Now let's see how they compare to our desired feature list: Laravel Forum uses a traditional forum structure, but Chatter takes a cue from Flarum's tag-based structure Both have a permissions system using Laravel's authorization Both have admin panels Neither has @mentions You absolutely need @mentions, so both of those are deal breakers. But wait! There's a package for that! Another quick search for "laravel mentions" brings up Laravel Mentions. (Do you sense a naming theme here?) Laravel Mentions allows you to set any text input or textarea as capable of @mentions, which is even better than if it was baked right into the forums! This allows you to reuse the same package for @mentions in both the forums and, for example, user profile comments! On the other hand, if you really do just need a lightweight forum solution and every available package has dozens of features you never intend to use (and that aren't written modularly so they can't be removed), then write your own! You want to weigh features you need against features a package has that you need and that you don't need. TL;DR Look for packages that reasonably fits your use case, but decouple features where possible (e.g. separating forums and @mentions) Extensibility Eventually, you might want to add notifications for things like receiving PMs, a subscribed thread getting updated, and news/announcements. This is best done via events and event listeners or some other kind of Observer pattern, where every notifying action dispatches an event, e.g. sending a PM dispatches PMSentEvent. Both Laravel Forum and Chatter dispatch events, so we're good to go there! An ideal third party package is easily extensible and configurable—maybe using traits, interfaces, or method hooks! But even easily extensible packages are useless if they don't document how you can extend them. TL;DR Look for packages that are extensible and have comprehensive documentation Stability & Ongoing Maintenance Assuming you're looking at a GitHub repository, click that Commits tab and note the frequency of commits and the dates of the latest commits. If there hasn't been a commit in over a year, that package might not be maintained, and it might not be patched if you encounter a major issue. This doesn't have to be a deal breaker—if the package has had a robust release cycle, is on a stable version, and doesn't appear to have many bugs, then it's probably safe to use. Now click the Issues tab to be taken to the repository's issues tracker. Take a look at the first page of issues. Are they tagged or marked by contributors, e.g. as "solved" or "not an issue"? Do most of them seem to be due to user error, e.g. migration errors? Then you're good to go! But if the top issue has three pages of users all reporting the same major issue, it's probably best to pass that one by. TL;DR Look for packages that actively maintained or have a stable release without any significant issues The Big List of Stuff You Shouldn't Write Yourself And example Laravel packages! Authentication (you should almost never write your own authentication! but Laravel 5 comes with its own auth system anyway) Forums (if you didn't get that already) Private messages Instant messages @mentions Tags Audits, model changelogs, and logging Authorization (Laravel devs are lucky enough to have that included in the core framework via guards) User verification (that register -> receive email -> verify registration workflow) Invite/Beta codes Friendship systems Online/recently online users Caching
  6. I'm looking to hire someone to write PHPUnit tests for my pet game framework to increase my code coverage. I'm paying $10USD per function that's completely covered. I have 241 of 966 functions already covered which means I have 725 more to go so that's potentially $7,250 if you want to go all out on them. I will pay weekly or bi-weekly through PayPal, whichever you prefer. You must be familiar with php, OOP and have written tests using PHPUnit before. If you do more than $400 worth of work and are a US citizen you must also be able to complete a 1099 for tax purposes. Experience with composer is a plus. Sample of the code base Sample Documentation (will help when writing tests) Sample unit test
  7. Hello! I am on the hunt for some mini-games to add to Celestial Equine. These games will be replicated/modified for each of the worlds. If you have games available, please post them here along with a price and description. I am able to swap out art, etc. Thanks in advance!
  8. A bit about me I am a full time freelance programmer and artist. I am an app developer by trade and have programmed sites from the ground up in the past. I have 3 years of schooling in game design and am looking for work on both short term and long term projects. I'm very flexible with pricing and am willing to work with reasonable budgets. Proficiency PHP // Symfony & Laravel HTML5/CSS3 // Bootstrap & HTML5 canvas Javascript/jQuery Node.js/socket.io Linux Servers Swift/Mobile app design Pricing $15 an hour. Sites I have programmed for Novilar, Mysticpets
  9. Introduction This is the second tutorial in my ‘MySQLi for Beginners’ series. If you haven’t already done so I would recommend starting with Part 1. MySQLi for Beginners Part 1 Prepared Statements Prepared statements can be complex to get your head around at first, but they’re really useful and can help remove a lot of potential issues when escaping user input. Prepared statements essential work by placing a ? where you want to substitute in user input, whether it be string, integer, blob or double. Prepared statements substitute the value into the SQL query so the issues with SQL injections are mostly removed. Define a Statement Let’s assume we want to write a query that returns all of the usernames from the users table where they have a name of Paul. Firstly, we’d define the SQL that we’re going to use: $sql = $db->prepare("SELECT `username` FROM `users` WHERE `name` = ?"); As you can see, that question mark is were we’re going to by assigning the name ‘Paul’ to. Bind Parameters We are going to use the bind_param method to bind a parameter to the $sql object. You must specify the type as the first parameter and then the variables as the second parameter. For instance we’d use ‘s’ as the first parameter for string, and the $name variable as the second parameter. $name = 'Paul'; $sql->bind_param('s', $name); If you have multiple parameters to bind which are of varying types we do the following: $name = 'Paul'; $age = '29'; $sql->bind_param('si', $name, $age); Please note the types are not separated like the variables are. Execute the Statement To execute the statement we would do the following. Not a lot to it really. $sql->execute(); Iterating over results To iterate over results we would first bind the result to variables, this can be done using the bind_result() method which allows us to specify the variables to assign the results to. If we assign the returned ‘username’ to to the variable $returned_username we’d do the following: $sql->bind_result($returned_username); Doing exactly as before, if you have multiple variables to assign to, you are able to comma separate them. Once you have bind the result variables, you want to go ahead and fetch the results. This is as simple as I have done in my MySQLi for Beginners tutorial – we’d use the fetch() method, which returns the values into the binded variables. while($sql->fetch()){ echo $returned_username . '<br />'; } Close $sql Once you are finished with your sql statement, it’s good practise to free the result to keep your code neat, clean and lean! $sql->free_result(); In my next MySQLi Tutorial I will cover MySQLi Transactions. This tutorial and more like it can be found on my company website: P S Web Solutions Ltd.
  10. Over the course of the next few weeks I am going to be showing you the Phaser framework and building a simple HTML5 game. This game will run on a mobile phone but it's important to point that Phaser is not a framework specific to the mobile domain, many developers, myself included are creating browser based HTML5 games to run on a desktop computer. As with any development, when using HTML5 to build a game you need to keep the performance limitations of the browser in mind, whether it be a mobile browser or a desktop browser. Using HTML5 to build a 3D game with HD graphics and loads of animations isn't a great idea - but if you want to build reasonably simple games like Candy Crush or Flappy Bird then this framework is a great choice. I've found Phaser to be one of the current most popular HTML5 game frameworks and is by far the most active framework on sites like www.html5gamedevs.com and is still being actively developed by Photon Storm. Considerations As we are developing for a mobile we need to consider the challenges that are unique to mobile when designing the game. Things such as: Although mobile is the intended device, different devices such as tablets and desktops with different screen sizes and resolutions can stll be used. The primary input method for the game will be touch. Consider how the user will play the game? Will the user be blocking most of the interface with their thumb when playing? Processing power will be very different to that of a desktop computer, there is also a difference between mobile phones these days. We will have access to features that the desktop may not, such as GPS and motion for example. If you apply these considerations to your game, the most obvious issue that springs to mind most of the time is do with movement. Will there be a need for the user/character to move in any direction, usually this is easily solved with a keyboard, but with a touch enabled device, that is no longer possible, therefore, our options then may include: Control the character by dragging with gestures. Create your own directional controls on the screen. Use the device to control the movement by tilting the device. There are a multitude of obstacles to overcome, such as dealing with the changing size of devices and how that will affect your game, hopefully over the course of this series we will be able to combat most of these issues. Now, let's get started! Configuring Your Environment We will discuss and deal with these issues as we get to them, but it's good to think of these things and consider potential approaches from the start. To start off with, I want to help you get your environment setup.Phaser needs to run on a web server and the best way to do this in your local machine. Once your web server is up and running, you will be able to store all your files locally and access them through http like: http://localhost/my-first-game instead of through the file system like this: file://C:/Users/Your-Username/my-first-game Using the file:// protocol will not work as it is much more restricted than the http:// protocol. There are various options available for getting a web server to run on your machine which you will be able to find via Google, but a great option and the one I always use is WAMP. If you are a Mac user, I hear XAMPP is a great alternative. Download and Install WAMP Once you have WAMP installed, please launch it and make sure all services are running by using the Control Panel in your system tray. A green W means everything is ok. Orange or Red signifies there is a problem that needs to be rectified. Anything you wish to able to access through localhost in your browser needs to be placed with the www of your install. On a default windows installation this is usually located at: C:\wamp64\www Download Phaser Phaser is very easy to download and setup. Once you get into the swing of development I would normally recommend you create a custom build that only includes the elements you need which is a great way of keeping the file size down but for now we will be downloading the full phaser installation. Go to the download page. Download the the js or the min.js version of Phaser. I personally recommend the js file as it can make debugging and error detection much easier. Creating a Game Skeleton Now you are up and running, it's time to get on with the first lesson. I am going to take you through setting up a skeleton for your Phaser project. This will be a generic set of files that can be used for just about any game. Once we are finished, I recommend you take a copy and keep this for future projects. A state in Phaser is JavaScript that runs a specific state within the game. For example a state might be the game title screen, another would be the game itself, and another would be the game over screen. In a more complicated game you may also have different states for different levels of the game. As well as the examples above, we also have states for booting and loading the game. The states you will be creating in your skeleton game are as follows: Boot This is the very first state as is invoked as soon as the game is launched/started. This is primary used to scale the dimensions of the game and to call the second state. Preload This is the second state and is used to load in any assets such as images, fonts, audio that the game needs to function. Once all the assets are loaded, the next state is triggered. MainTitle The MainTitle state is used to display the game title. This will usually display the title of the game and maybe a graphic that says Play or Start that acts as a button. As you get more comfortable with development you could expand this further and add an instructions button that would open a popup or perhaps a Tutorial state. Main The Main state contains all the juicy parts of the game and allows for actual game play. GameOver Once the player dies/wins they will automatically trigger the GameOver state. This screen is used to display the final score and give them an opportunity to start a new game. The reason I like to use states as it prevents all the code in one giant state. This allows us to make it more modularised, more readable and organised. It also makes future updates a hell of alot easier. Setup Your Game Start by createing a new called game-skeleton in your web server root. Inside that folder create two more folders: assets js Copy the downloaded phaser.js/phaser.min.js files into the js folder create above. Now you have the above structure, we will begin creating each of the states we discussed above. Create the Boot State Create a file called boot.js inside of your js folder and copy the following to it: var Boot = function(game){ }; Boot.prototype = { preload: function(){ }, create: function(){ this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; this.scale.setScreenSize(true); this.game.state.start("Preload"); } } This state will set the screen size to fit the device that you are using and then trigger the "Preload" state. The boot state will only run when the game is first launched and will only run once. Create the Preload State Create a file called preload.js inside of your js folder and copy the following to it: var Preload = function(game){}; Preload.prototype = { preload: function(){ }, create: function(){ this.game.state.start("MainTitle"); } } This will state will would normally have more code that will load in the assets required for your game. For the time being we will just be calling the next state. Create the MainTitle State Create a file called maintitle.js inside of your js folder and copy the following to it: var MainTitle = function(game){}; MainTitle.prototype = { create: function(){ }, startGame: function(){ this.game.state.start("Main"); } } The MainTitle state has a create method that will run when the state is triggered. This will be used to create the title screen which will contain some form of graphic and a start/play button that calls startGame function which triggers the Main state. Create the Main State Create a file called main.js inside of your js folder and copy the following to it: var Main = function(game){ }; Main.prototype = { create: function() { }, update: function() { }, gameOver: function(){ this.game.state.start('GameOver'); }, }; The Main state is where all the magic of your game happens. It is responsible for the running of the game. A gameOver method is for triggering the next state when we are ready. You will notice this state has a new update method that will constantly loop every frame refresh. The initial state of the game will be done in the create method, but alot of the logic will be in the update method. The update method will be used to call the gameOver method, for example if a player is colliding with an enemy. Create the GameOver State Create a file called gameover.js inside of your js folder and copy the following to it: var GameOver = function(game){}; GameOver.prototype = { create: function(){ }, restartGame: function(){ this.game.state.start("GameTitle"); } }; This is the final state. We use the create method which will create the Game Over screen as well as an additional method that will allow the user to restart the game. When we leave the state and come back to it later it will be refreshed. Moving between states destroys anything created previously, it is like starting a fresh each time a state is called. However, it is possible to create some persistence throughout the game using local storage, which i'll be sure to cover at a later date. Bring it all Together Create an index.html file in the root folder of your project and add the following code: <!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>I Hate Squares</title> <script type="text/javascript" src="js/phaser.min.js"></script> <script type="text/javascript" src="js/boot.js"></script> <script type="text/javascript" src="js/preload.js"></script> <script type="text/javascript" src="js/gametitle.js"></script> <script type="text/javascript" src="js/main.js"></script> <script type="text/javascript" src="js/gameover.js"></script> <style type="text/css"> body { margin: 0; } </style> <script type="text/javascript"> (function() { //Create a new game that fills the screen game = new Phaser.Game(window.innerWidth * window.devicePixelRatio, window.innerHeight * window.devicePixelRatio, Phaser.AUTO); //Add all states game.state.add("Boot", Boot); game.state.add("Preload", Preload); game.state.add("MainTitle", MainTitle); game.state.add("Main", Main); game.state.add("GameOver", GameOver); //Start the first state game.state.start("Boot"); })(); </script> </head> <body> </body> </html> The Javascript is responsible for initialising the game. To create an instance of a Phaser game we call Phaser.Game() and supply it with the width and height of our game, as well as the rendering engine we wish to use. As well as providing a height and width, we can also supply the devicePixelRatio which is handy for mobile games as it allows the game to scale properly. As I mentioned, we also supply which rendering engine we want to use to the Phaser.Game() call. This can either be WebGL or Canvas, if we set it to AUTO then it will use WebGL if available, but fall back to Canvas if it is not available. Once we have initialised our game, we add all of our states to the game and trigger our first state. This will then start the chain reaction of calling the states we created before: Boot calls Preload which calls MainTitle which calls Main which calls GameOver which then calls MainTitle once more. This is the end of Part 1 and you now have a blank skeleton application that you could use for just about any game. Feel free to Follow Me to get notified for the next installment. This tutorial and more like it can be found on my company website: P S Web Solutions Ltd.
  11. Introductions Most of the sites you visit these days have some sort of database storage behind them. Most sites that use PHP will opt to use a MySQL database. You are able to interact with your MySQL database using the MySQLi class. MySQLi will only work with a MySQL database, whereas if you were to use PDO, it will work with various different database systems. MySQLi can be coded via objected oriented or procedural. Today I am going to be looking at the object orientated approach. PHP MySQLi Class Connecting Connecting to a MySQL database is done by instantiating a new instance of the MySQLi class. $db = new mysqli('localhost', 'username', 'password', 'paulsonny-demo'); if($db->connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); } The database name parameter is optional and can be left out. Please note, if you do leave the database name parameter empty then you will need to prefix all of your tables in your queries with the database name. Querying Let's assume we have a users table in our database and we wish to retrieve them all. $sql = "SELECT * FROM `users`"; if(!$result = $db->query($sql)){ die('There was an error running the query [' . $db->error . ']'); } The above will give you a $result variable that contains a mysqli_result object. Once we have the mysqli_result object we are able to loop through the results, perhaps displaying them to the user and then freeing up the result. Query Results If you wanted to loop through the results and show them to the user with each row being on a new line we'd do something like the following: while($row = $result->fetch_assoc()){ echo $row['username'] . '<br />'; } # of Returned Rows Each mysqli_result object that is returned from the database as a variable which is called num_rows. This can be accessed by doing the following: <?php echo 'Total results: ' . $result->num_rows; ?> # of Affected Rows When you are running an UPDATE statement, you may sometimes wish to know how many rows have been updated. The mysqli object has a variable called a affected_rows which can be accessed as follows: <?php echo 'Total rows updated: ' . $db->affected_rows; ?> Free the Result Once you have finished with your result set, it is recommend that you free the result. This would be placed after our looping over the records. $result->free(); This will free up some system resources, and is a good practice to get in the habit of doing. Escaping characters When inserting data into a database, it is recommended to escape it first, so that single quotes get preceded be a backslash. This will mean that any quotes won't break out of any that you use in your SQL. You should look to use the below method: $db->real_escape_string('This is an unescaped "string"'); However, because this is a commonly used function, there is an alias function that you can use which is shorter and less to type: $db->escape_string('This is an unescape "string"'); This string would now be safer to insert into your database through a query. Close Database Connection Don't forget, when you've finished with your database to make sure that you close the connection: $db->close(); PHP MySQL Class If you are using the functions mysql_connect() or mysql_query() then I would recommend swapping to the above. Any functions prefixed with mysql_ are actively discouraged by PHP themselves. In my next MySQLi Tutorial I will cover Prepared Statements. This tutorial and more like it can be found on my company website: P S Web Solutions Ltd.
  12. How to think about Level's by ignoring them in your Game This guide is designed to introduce a concept in how a game maker can think about levels in their game, by simply ignoring them all together (at least internally). Now leveling systems in games can be simple or complex, and this is only one method that I have found successful in my games (and is used in the Adoptables system here on the Forums), for the following reasons: It is simple to use and easy to store. It doesn't care about what stage the character or pet is in at any point. It is forward thinking and easily adaptable. It is level agnostic (no level cap). How does it work in conceptual terms? It works by not caring when you reach a level, and by keeping a value that is incremented (we call it Power here on the forums, but you can call it whatever). This is an always incrementing number, and it doesn't reset when a threshold is met. Based on this number we can then create thresholds that signify importance to us (i.e. Levels). This reduces code, data storage, and the complexity of the code. As opposed to caring when we hit a level, we only care about changing something outside of it when a threshold is met. What does my data structure look like? If you were to look at this in terms of a database, you would have two tables (yes, only two!) that could manage your entire pet level / evolution system. This makes life much easier to manage things. character id ... (name, description, gender, whatever) stage_id power stages id min_power parent ** stages_id, power, min_power, and parent will be stored as INT, or BIGINT in terms of a database storage system. I am assuming the main usage of MySQL for this example, but adjust accordingly. How does this work in practical use? You would use this very simply by simply adding to the character's power column any amount of experience you wish to give them, then checking that amount against min_power in stages. Here are two snippets in PHP that show how this works in action, note that I use the parent column here to keep my stages within the concept of evolved trees (so I can branch evolutions into different areas if I choose to): <?php class Character { private $_db; /** * Constructor * * @param [PDO] $_database This is the database PDO object to query the database with. */ function __construct($_database = NULL) { $this->_db = $_database; } /** * Returns the character data. * * @param [int] $id * @return object */ function get($id) { return $this->_db->prepare('SELECT * FROM characters WHERE id = ?') ->execute([$character_id]) ->fetch(PDO::FETCH_OBJ); } /** * Returns a stage row from stages. * * @param [int] $id * @return object */ function get_stage($id) { return $this->_db->prepare('SELECT * FROM stages WHERE id = ?') ->execute([$id]) ->fetch(PDO::FETCH_OBJ); } /** * Returns a boolean value indicating whether or not a theshold to level up can be achieved. * * @param [int] $character_id * @return boolean */ function can_evolve($character_id) { $character = $this->get($character_id); $stage = $this->get_stage($character->stage_id); // This will return a result if we have successfully hit a threshold, or FALSE if we have not based on information in the stages table. $next_stage_power = $this->_db->prepare('SELECT min_power FROM stages WHERE id != ? AND parent = ? AND min_power >= ? AND min_power <= ? ORDER BY min_power ASC') ->execute([$stage->id, $stage->parent, $stage->min_power, $character->power]) ->fetch(PDO::FETCH_OBJ); // Have we hit a threshold in the stages table yet to evolve or level up? if($next_stage_power !== FALSE) { if($character->power >= $next_stage_power->min_power) { return TRUE; } else { return FALSE; } } else { return FALSE; } } /** * Returns the next stage(s) once leveling is available. * * @param [int] $character_id * @return [array] object */ function get_next_stages($character_id) { $character = $this->get($character_id); $stage = $this->get_stage($character->stage_id); $next_stage_power = $this->_db->prepare('SELECT min_power FROM stages WHERE id != ? AND parent = ? AND min_power > ? ORDER BY min_power ASC') ->execute([$stage->id, $stage->parent, $stage->min_power]) ->fetch(PDO::FETCH_OBJ); // This gets the next stage available to evolve, but only if it is available. If more then one stage is available, more then one row is returned. return $this->_db->prepare('SELECT * FROM stages WHERE id != ? AND parent = ? AND min_power = ?') ->execute([$this->_data['pet_stage_id'], $current_stage->parent, $next_stage_power]) ->fetchAll(PDO::FETCH_OBJ); } } Note: This code is for reference only, I re-wrote it from a different form then it is for this forum (this forum uses a custom database wrapper), so it is for reference use only. It is to give you an idea of how this can be implemented. In short: In the above case, when it comes to updating a character's stage or level, I would check if they could by calling can_evolve($id), if TRUE, I could get the available stages, then set my characters stage_id column to whatever was available that I wanted to. I don't need to manage power at all during the leveling process. In conclusion: This is one of many ways to deal with leveling up something in a game, I find this the easiest way since it is a very simple mechanism that is forward thinking, and easy to implement from a sense of database and code, and flexible enough that what happens when a level threshold event happens - I don't have to worry about what it means in terms of experience - I just have to change what is needed to level up. As always, I would love some feedback, this is kinda the first guide I have written in forever, and is probably quite dry unless you are familiar with some coding concepts.
×
×
  • Create New...

Important Information

By using this site, you agree to our Guidelines, Terms of Use, and Privacy Policy.