troublesum's Forum Posts

  • Make sure your ecapsulating the php array in the format that the C2 array is expecting.

     $myArray = array();
        $myArray[] = 4;
        $myArray[] = 3;
        $myArray[] = 1;
        $myArray[] = 3;
        $myArray[] = 1;
    
        $output = array(
    	'c2array' => true,
    	'size' => array(
    	    0 => count($myArray),
    	    1 => 1,
    	    2 => 1
    	),
    	'data' => array()
        );
    
        $x = 0;
        foreach ($myArray as $value) {
    	$output['data'][$x] = array();
    	$output['data'][$x][0] = array();
    	$output['data'][$x][0][0] = $value;
    	$x++;
        }
    
        return json_encode($output);
    [/code:1gjt5210]
    
    The resulting JSON string would look like this :
    {"c2array":true,"size":[5,1,1],"data":[[[4]],[[3]],[[1]],[[3]],[[1]]]}
    
    You can now take this string as is and load to the Array in C2
  • I've never tried it but this site claims to offer what you would need to turn your laptop wireless connection in to a wireless access point providing a link between it and other wifi enabled devices (your cell phone) via wireless network connection.

    http://virtualrouter.codeplex.com/

    Good luck.. let me know if this works.

  • You got it.. just change the version number every time you publish a new version of the game and the browsers will grab the new file instead of using a cached one.

  • There is only one method im aware of to accomplish this but I dont think C2 has any ability to do this. The trick is to append a parameter/string to the file name in the script tag (assuming your hosting your files) and change it when you file changes.

    Example:

    <script src="myfile.js?version=1.0"></script>

    The browser interprets the whole string as the file path even though what comes after the "?" are parameters. So next time you update your file just change the number in the script tag on your website (Example <script src="myfile.js?version=1.1"></script>) and each users browser will see the file has changed and grab a new copy.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ex value = 183

    round(value/10)*10 = 180

    Ex value = 187

    round(value/10)*10 = 190

  • I use a 3rd party plugin for the moveto function but this is what i do.

    Create SpriteFont and give it behavior fade and set the fade out params. So by default as soon as i create the object anywhere on the screen even if i don't move it it will disapear in just under a second and destroy itself. Then assign the moveto behavior and give it a speed so as i spawn it i can tell it where to move (up down left, etc..)

    [attachment=1:1bfz9a2l][/attachment:1bfz9a2l]

    Next I create a function that spawns the object where i want and tell it to move up 100 pixels. (just enough so that by the time it reaches its destination is faded out)

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

  • 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

  • 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