Sestenes's Recent Forum Activity

  • I posted this on your other thead but wanted to reply to this one as well.

    Make sure your encapsulating 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:2hjte4hn]
    
    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
    

    How would you format your json_encode($output) if all you want to do is return, say, five name/value pairs?

  • I am having a similar issue. I'm not sure how to convert an AJAX request into an array and pull the data from it. I want simple name value pairs, so I assume I want a 2D array. The file that the AJAX request is sent to works fine when all I do is echo a single variable and set it to a variable in C2, but when I try echoing an array, such as:

    header('Content-Type: application/json');
    	$output = array(
    		'c2array' => true,
    		'error' => false,
    		'userID' => $ID
    	);
    	echo json_encode($output);[/code:fr0da6hw]
    
    and capturing it in C2 with AJAX On "tagname" completed -> Array Load from JSON string AJAX.LastData, I get tripped up. I assume that I'm either not loading it to an array in C2 properly, not setting up my array in C2 properly, or I just don't know how to pull the data from the C2 array properly.
  • Wow, that's embarrassing. Thank you very much for the help!

  • [attachment=0:2jrtvksb][/attachment:2jrtvksb]

    I understand how to install the plugin - I can interact with it inside of C2. I guess I'm just at a loss for how to get it to work. Is it as simple as setting the value of a variable to CBhash.MD5("data"), or do I need to prime that variable somehow? Does the plugin need to be initiated in any way? There must be something I'm missing.

  • I just updated to the latest version of C2, and I also just downloaded the version of the MD5 Hash plugin that I found in the first post of this thread, and I'm getting no love. Is there a more recent version of the plugin I should be using?

  • I've been looking for a way to do this for some time now. I kept seeing something about "jump sustain" - not sure if that was in Construct Classic or what, but this trick works for C2.

  • Thank you very much, Guizmus! I was hoping to find a similar answer in this forum and was lucky enough to stumble upon your posts here. Good stuff!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey that's a great idea - thanks for sharing!

  • Yeah, I thought I'd give my powerup objects the boolean instance variable (named "used"). When the player tags a powerup it is destroyed and the boolean is tripped (used = true). When a layout loads, if the object's "used" variable is true, destroy that instance of the object.

    It works, but I'm running into the same problem of not being able to restore those objects on a game over. Even if I set their boolean values back to "used=false".

    Would love to hear of a way to reset persistent object's instance variables!

Sestenes's avatar

Sestenes

Member since 23 Apr, 2014

None one is following Sestenes yet!

Connect with Sestenes

Trophy Case

  • 10-Year Club

Progress

10/44
How to earn trophies