AJAX via JSON to ARRAY

Get help using Construct 2

Post » Fri Jun 22, 2012 12:55 pm

Right, the textbox requires text and the array contains numbers. Try setting it to

str(array.at(0,0,0))
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Fri Jun 22, 2012 1:08 pm

the result in the text box is 0 if i transform it to a string, not 300.
Is there any way to get a log or debug information?

B
7
Posts: 11
Reputation: 1,022

Post » Mon Oct 01, 2012 2:01 pm

Hi,

i got the same Problem. If i convert it to String there is a 0 displayed not the numbers inside.
There must be an answer for that.

Kind Regards

MCSell ;)
MCSell2012-10-01 14:01:56
B
8
S
3
G
4
Posts: 2
Reputation: 2,492

Post » Fri Oct 23, 2015 4:59 pm

I know it is an old post, but looking for an answer I came here.

I could resolve it, the Json format its a must.

My php to fill a 2 dimension array:
$data is an asociative array, each row has an array with 3 key => value data: id:number, name:string, points:number. It's for a ranking.
Code: Select all
    $rows = count($data);
    $cols = 3;
    $depth = 1;
    if (!empty($data)) {
        $datos = '{"c2array":true,"size":[' . $rows . ',' . $cols . ',' . $depth  . '],"data":[';

        foreach ($data as $fila) {
            $datos .= "[";
            foreach ($fila as $key => $value) {
                $datos .= '["' . $value . '"],';
            }
            $datos = rtrim($datos, ",");
            $datos .= "],";
        }
        $datos = rtrim($datos, ",");
        $datos .= "]}";
    }


Code: Select all
{
    "c2array":true,
    "size":[3,3,1],
    "data":
    [
    [
        ["4"],["mark"],["299"]
    ],[
        ["2"],["steve"],["23"]
    ],[
        ["3"],["bill"],["3"]
    ]
    ]
 }



Then, you can access all data in array.
Name: arrRanking.At(X,1,0)
Points: arrRanking.At(X,2,0)

I tried to loop filling 10 text boxes but I don't know how... yet jiji. :lol:

UPDATE: Now I could fill the text boxes in a loop.

You only need a instance variable in the text box.

Image

Alek
Last edited by alegalviz on Tue Oct 27, 2015 1:37 pm, edited 1 time in total.
B
3
Posts: 1
Reputation: 177

Post » Fri Oct 23, 2015 7:43 pm

Padman wrote:hi ramones, did not work.

just to verify, that is what i have done:

step one:
created array in construct with properties:
width: 1
height: 3
depth: 2

step two:
loaded this string via ajax:
{
"c2array":true,
"size":[1,3,2],
"data":[
     [ [300],[25] ],
     [ [100],[50] ],
     [ [800],[10] ]
]}

as i understand now the size is similar to the array in construct, so
- "size":[width,height,depth] - correct?

step 3
use the function Load from JSON string with ajax.lastdata (or the string itself)

step4
set debug.text to array.at(0,0,0)

array.at(0,0,0) should be 300, right?

If i get this thing working i will write a tutorial about it -.-'
otherwise i have to fill my array with a splitted string... Padman2012-06-22 06:50:08


Unless i misunderstood (which is often) If you set your json to "size":[3,2,1] instead of "size":[1,3,2] it should work, it gets 300 from array.At(0,0,0), therefore array.At(2,1,0) = 10 I have provided a capx here.

http://www.sizzle-games.com/Ajaxtestarray.capx

Also if you set your file to
{
"c2array":true,
"size":[3,2,1],
"data":[
[ ["cat"],[25] ],
[ [100],[50] ],
[ [800],[10] ]
]}
array.At(0,0,0), will return cat
B
27
S
5
Posts: 163
Reputation: 3,383

Previous

Return to How do I....?

Who is online

Users browsing this forum: DemantDigitalArt, mjj1990 and 7 guests