0 Favourites

How do I Set a instance variable with an external file?

  • How do I Set a instance variable with an external file?

    I have this file

    {
        	"damage": 2,
        	"resistance": 16,
        	"health": 1,
        	"speed": 1,
        	"acceleration": 20,
        	"traillength": 0,
        	"wavethreshold": 0,
    	"homingthreshold": 0,
        	"selfdestruct": 1,
    	"armingtimer": 0,
        	"explosiontype": -1;
    }
    
    [/code:gkyoyiac]
    
    and I need to load it and set it to the instance variables
  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Where exactly have you stucked? You can load data for example using AJAX if it is a PHP output. Then parse output to string without "new line" characters and set it as a value of your text type instance variable.

  • I'm not sure what you mean by PHP output

    I am using a .json file to do this

  • I'm not sure what you mean by PHP output

    I am using a .json file to do this

    Have you looked at Yann's Json plugin in the extending C2 section of the forum? I belive that would be worth looking into for you. However you can with a few adjustments change the json syntax to be used in a dictionary object.

    {"c2dictionary":true,"data":{
    "damage":"2",
    "resistance":"16",
    "health":"1",
    "speed":"1",
    "acceleration":"20",
    "traillength":"0",
    "wavethreshold":"0",
    "homingthreshold":"0",
    "selfdestruct":"1",
    "armingtimer":"0",
    "explosiontype":"-1";
    }
    [/code:nn2rsoib]
    
    Then import that into your project files folder. Use AJAX to load project file then on success have your dictionary load that json from Ajax.LastData
    
    In your game just call from that dictionary and change the keys according to any effect the player may have on them. Also cool thing is you can save that dictionary as a json and reverse the process to save your game. 
    
    Also when using files inside C2 best to leave them a .txt C2 will be able to tell the difference between formats like php, json, and sql
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)