Forum rules - please read before posting.

How easy is it to add server interaction?

Hi,

I'm fairly new to Unity, and haven't bought AC yet, only considering it. It looks awesome, but I have two questions before I jump on board:

1, How easy is it to save the status of a game to a server on the Internet? For example, a PHP script that will store the game state in a database. I'm familiar with PHP, so it's the Unity/AC side that this question is focused on. (And of course, load from this server, too.)

2, Similar to the above, I would like to be able to set in-game variables, based on data from a PHP script. (For example, if the user is logged into my website, they can access certain parts of the game, otherwise they cannot.)

Thank you,

Ati

Comments

  • edited May 2020

    Welcome to the community, @Ati.

    How easy is it to save the status of a game to a server on the Internet?

    You'd have to incorporate your own custom scripting to do this, since AC's built-in save method is to write to either a system file, or in Unity's PlayerPrefs. Aside from the PHP to handle the server communication, you'd also need to write a C# script to handle the AC/Unity side of things.

    Through such scripting, it's possible to create both custom save formats, and file locations, by writing scripts that implement AC's iSaveFileHandler and iFileFormatHandler classes.

    You can learn more about this in the Manual's "Custom save formats and handling" chapter, but the iSaveFileFormatHandler essentially allows you to define Save / Load functions, with the actual save data provided as a string.

    Here's a sample of the class that uses this to provide saving to the PlayerPrefs:

    https://paste.ofcode.org/uJpqDh2EHkswdemgkyCmfW

    Implementing iFileFormatHandler similarly lets you store save data in a custom file format, with the provided formats being XML, Json, and Binary.

    Similar to the above, I would like to be able to set in-game variables, based on data from a PHP script.

    The server communication aspect, again, would have to be done via custom scripting - as AC doesn't have built-in server functionality. However, if you are able to separately access online data, then it's trivial to set AC Variable values through script. See too the Manual's "Variable scripting" chapter for examples.

    If you're undecided and haven't yet purchased AC, I would say it's probably best to focus on the Unity / server connection side of things first, so that you already have the ability to grab e.g. variable values from a server before adding another layer of complexity with AC.

  • Thank you for the detailed response, Chris!

    Looks like I'll have to do some learning in Unity. :)

    The more tutorials I watch about AC, the more its possibilities blow my mind. Wow!

    This is going to be awesome! :)

  • AtiAti
    edited June 2020

    Here's a sample of the class that uses this to provide saving to the PlayerPrefs: https://paste.ofcode.org/uJpqDh2EHkswdemgkyCmfW

    Oh-oh, I just got on board the AC-train, and this code has already expired before I could use it. :( Chris, could you please post it again? I got the rest sorted (load variables from server, send custom variables to server), I just need to save to/load from the server, and that'll be it, I'll be ready to start my story. :) Thanks!

  • No problem, here you go:
    https://paste.ofcode.org/skZhWuczNenFAqfabw674k

    If/once you get AC, this is adapted from the SaveFileHandler_PlayerPrefs.cs script file - I've just removed the non-essentials to make the core idea more clear.

  • Thanks a lot!

    I bought AC a couple of days ago. :) It's awesome!

  • I completely got rid of the save/load menus, and everything is automatically saved to/loaded from a server. This way people can continue playing on a different browser than where they started (work/home, for example).

    I have one more question before I do anything reckless. :)

    I'll be doing a 2D game with 100+ scenes, 100+ items, dozens of NPCs, maybe even multiple Player characters. Hopefully, a lot more of everything later as the story progresses. So far I've been playing with two scenes, and save times are fine, but obviously this is nowhere near what I'll be getting with a complete game.

    How big can save files get in circumstances similar to the above? And how quickly does AC gather everything to be included in the save file in such cases?

  • How big can save files get in circumstances similar to the above?

    AC's save data is essentially split into two categories:

    1. Data it knows it needs to save
    2. Data you tell it that it needs to save

    For 1), this is things like the Player's position, inventory, global and local variable states, etc. Basically anything scene-independent, so it generally won't scale with the number of scenes you have (outside of local variables).

    For 2), this is any scene object that's been flagged up with a ConstantID or Remember component. The Manual's "Saving scene objects" chapter for more on this, but each component will tell AC what data about that object should be saved. So it's really the number of such components, rather than the number of scenes, that will determine how much data is saved.

    It's hard to put a number down so far as actual filesizes go, but such components typically aren't much. You can, though, reduce the number of Remember components needed by re-initialising your scene's OnStart/OnLoad cutscenes based on the values of local variables.

    And how quickly does AC gather everything to be included in the save file in such cases?

    AC will keep track of all previously-visited scene data as it goes, so it'll already have most of what it needs to save to hand. Again, it's hard to give real numers here, but the speed of saving a scene is a factor of number of Remember components present.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.