Using AJAX object with ASP.NET WEB API

2

Index

Stats

12,173 visits, 29,063 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 8 Dec, 2014. Last updated 12 Oct, 2020

Converting a C♯ object to Construct Dictionary format

First Pass: Visual Studio

Now you are ready to use the Construct2Convert.ToDictionary() inside a Controller Action to convert objects or collections, like arrays, to the Construct Dictionary data format, example:

    // An example object with the data to be sent to the game
    PlayerData playerData = new PlayerData();
    playerData.PlayerName = "John";
    playerData.HiScore = 999;

    // Use WebAPI2Construct to transform your data in a Construct readable format
    var playerDataJSONDictionary = Construct2Convert.ToDictionary(playerData);

    return Ok(playerDataJSONDictionary); // Send the data to the game

Second Pass: Construct

1. When in Construct, use an AJAX object Request URL action to request the data to ASP.NET WEB API project that still runing in Visual Studio, or hosted in a web server.

2. Catch the data in the game using the AJAX On completed event.

3. Use a Dictionary object Load action to load the data from the AJAX.LastData variable.

4. After that you be able to read your data from inside the Dictionary.

Why using Construct Dictionaries?

By using a Dictionary you will be able to send more complex data to the game at the same time.

Learn more at WebAPI2Construct project's website at GitHub

  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!