troublesum's Recent Forum Activity

  • jayderyu

    As I understand the priority to C2 is.

    anything not part of the IDE. ie stuff that requires C++ programming. Some get's done. But it's much farther between. Plugins and logic flow(ie JS) get's worked on more.

    That's a shame. There are some simple things I would really love the IDE to do that would make navigating code and debugging so much easier. Multiplayer was an epic addition and it's great that I can more easily add shadows now but damn i wish the IDE would just highlight my search results when looking for usages I'm debugging or offer a collapse all on functions like it does for groups.

  • farflamex - Not a problem... I enjoy helping when i can

    So once the player data is received to PHP via POST its nothing more than an array of data. Its not any sort of real object (yet). If the array data you receive from the POST is already relative to the columns your updating in your database table (IE Player1.Score, Player1.Health, etc..) which are just basic properties that have no affect on other properties when updating then Objects aren't really necessary IMO.

    It would how ever make sense to do OOP (Build player objects) if at the time you receive the POST data, before you do anything with the array data, you first query the database and retrieve the player data and build the player objects with the SQL information. Then using methods from your player object you update the player with the new data you received from the array. IE $player1->AddExperience(10) which will update the database using some custom algorithm that may affect other player properties as a result of adding experience like attack level, defense level etc. all of which are updated by a signal command to "AddExperience" . If your player objects are complex like that then this would give you a standardized method of making changes to SQL data by working through the object. The issue is that the player then needs to be updated in C2 with the new information as well so there is lag in the time the player will achieve his new experience as he had to wait for PHP to do the processing. So if its a real-time achievement this probably wont work but if its an achievement at the end of round that is applied to the next round it would be fine.

    Personally I feel you should keep your objects in C2 and do all of your processing there instead of in PHP and instead PHP is just the wrapper for storing/retrieving information to/from the database. (As a developer it kills me to have to do this in the event sheet as its not really meant for this so I have to work around or hack to get the results i want) But If you also know JavaScript then what I would do (which I do) is create plugins that become your player object methods that allow you to write code for these complex events instead of trying to piece it together in the event sheet. If you really want to unlock the power of C2 you will need the ability to write JavaScript and create your own plugins to perform complex functions.

  • Ahh.. looks like beta releases check for correct closure syntax... yah the error is trivial.. its a tag that makes the text italic when displaying an action in the editor. I found the error thanks to your print out and updated the file in the post above. You can re down load it and it should work.

    Thank you!

  • Possibly... I do only install the stable releases of C2 soim not on the latest (174).. try saving and re-opening and see if the error comes up. I don't have any errors when I open it so if you still get them upload a screen shot for me if you can. Thanks

  • farflamex I dont know how you feel about using 3rd party plugins but I also found that I didnt like the way Dictionaries and Arrays were stored in C2 so I created my own Table plugin that works with raw JSON data.

    [attachment=0:1bsug4ht][/attachment:1bsug4ht]

    Example:

    [attachment=1:1bsug4ht][/attachment:1bsug4ht]

    You can see in this example I just set my values and then can pass the entire table AsJSON how ever unlike C2 Arrays its pure JSON data with no additional overhead and is a named array storage instead of indexed integer values. Its basically the same as any array (hash table for those that prefere correct my symantics) your familure with working with in PHP.

    $jsonString = $_POST['c2Data'];
    
    $array = json_decode($jsonString,true);
    
    //$array['Player1']['Name'] = 'Troublesum' (string)
    //$array['Player1']['Score'] = 1000 (int)
    //$array['Player1']['Health'] = 100 (int)
    
    //$array['Player2']['Name'] = 'Not Troublesum' (string)
    //$array['Player2']['Score'] = 500  (int)
    //$array['Player2']['Health'] = 20 (int)
    [/code:1bsug4ht]
    
    You can see its much easier to work with and the value types (string),(int) are maintained. If your interested in using the plugin your more than welcome to. I have attached it above with a few examples on how to use it.
  • farflamex So there is nothing wrong with making your own strings and exploding them into arrays on the PHP side if that's what your comfortable with. The Problems they didn't explain is that if for any reason one of your values happens to contain a character that is the same as your delimiter (in this case a "pipe" | ) then it would break your method. Obviously you would make sure that never happens but its possible and a limitation. Also by using JSON you keep the value type such as is its a string, int boolean, etc.. for now your always going to have strings by exploding your custom "pipe" delimited string. Again there is nothing wrong with creating your own custom strings and in truth we all start out doing it that way (Every beginning PHP developer probably starts out doing that) but as you get better and can do more you will suddenly need more and that's when you start using JSON to pass information. I say go with what your comfortable with until it no longer provides enough flexibility and then move up JSON when your ready. The only thing is that if you perfectionist you will want to go back and fix all your legacy code that uses out dated methods once you decide to start using JSON

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ok so imagine you have a 2 dimensional array (x,y)

    [attachment=0:3lub0k77][/attachment:3lub0k77]

    AsJSON the string would look like this

    "{"c2array":true,"size":[2,2,1],"data":[[["Hello"],["World"]],[["Good"],["Bye"]]]}"

    So to decode it 2 dimensional in PHP you would do this

        //Just to see what it will look like 
        //$_POST['c2Data'] = "{\"c2array\":true,\"size\":[2,2,1],\"data\":[[[\"Hello\"],[\"World\"]],[[\"Good\"],[\"Bye\"]]]}";
        
        $jsonString = $_POST['c2Data'];
        
        //Have to set to true so json is converted to array and not an object
        $jsonAsArray = json_decode($jsonString,true); 
        
        $c2ArrayData = $jsonAsArray['data'];
        
        $output = array();
        foreach ($c2ArrayData as $zIndex => $zRow) {
    	      $output[$zIndex] = array();
    	      foreach ($zRow as $yIndex => $yRow) {
    	             foreach ($yRow as $xValue) {
    		          $output[$zIndex][$yIndex] = $xValue;
    	            }
    	      }
         }
    
        //$output[0][0] = "Hello"
        //$output[0][1] = "World"
        //$output[1][0] = "Good"
        //$output[1][1] = "Bye"
    
    [/code:3lub0k77]
  • Yeah.. just add it to the data string and assign it to a variable in the data string.

    In this example I packaged the array.AsJSON in the "c2Data" POST variable by typing in "c2Data="

    [attachment=0:znwa8ify][/attachment:znwa8ify]

    You can use this to parse an array with only the x dimension set

        //$_POST['c2Data'] = {"c2array":true,"size":[3,1,1],"data":[[[60]],[[10]],[[20]]]}
        $jsonString = $_POST['c2Data'];
        
        //Have to set to true so json is converted to array and not an object
        $jsonAsArray = json_decode($jsonString,true); 
        
        //$jsonAsArray['data'] = [[[60]],[[10]],[[20]]]
        $c2ArrayData = $jsonAsArray['data'];
        
        //$c2ArrayData = [[[60]],[[10]],[[20]]]
        $output = array();
        foreach ($c2ArrayData as $z) {
    	     foreach ($z as $y) {
    	            foreach ($y as $x) {
    		          $output[$y] = $x;
    	            }
    	     }
        }
        
        //$output[0] = 60
        //$output[1] = 10
        //$output[2] = 20
    
    [/code:znwa8ify]
    
    Edit: I see now you wanted a 2d example.. give me sec to type it up and ill be back
  • I dont think there is a limit. As a web developer I can say ive posted json strings that contain thousands of rows of array data back and forth between javascript and php. C2 should be no different. Just add it to the URI string what ever the length and you should be fine

  • Others might have a better way but i created a plugin for me to do this as well. Its basically a 3 dimensional named array (hash table) with a ton of features. But it supports merging/loading JSON objects and retrieving data by key name. Your well come to give it to try

    Example for what you doing: (Note its a 3 dimensional array so since the JSON object is 2 dimensional the data was loaded to "default"

    [attachment=1:5ccyf6gw][/attachment:5ccyf6gw]

    Here is the plugin and the example capx

    [attachment=0:5ccyf6gw][/attachment:5ccyf6gw]

  • Ninetendoo - Thanks but i would consider it settled. I'm not going to release it per his wishes. But the capx (which doesn't use the plugin but is what the plugin is based off of) at least provides a foundation for anyone that wants learn about the method.

  • farflamex Glad it helped.. The reason for the nested for-each loops is because the c2 array object is 3 dimensional and your based on the string the data values were in the 3rd dimension of the array so you have to dig into each level to find it and separate it.

troublesum's avatar

troublesum

Member since 4 Dec, 2013

Twitter
troublesum has 2 followers

Trophy Case

  • 11-Year Club
  • Email Verified

Progress

12/44
How to earn trophies