Vallar's Forum Posts

  • Here's an example. You would replace the localstorage events with whatever your server uses.

    https://www.dropbox.com/s/3diz2xukc4732zg/LocalstorageSaveArrayExample.c3p?dl=0

    Oh, wow, thank you very much. That explains it pretty well.

    I wish this forums had some kind of kudos system :D. Thanks again!

  • I think I understand...

    Like I said earlier, the simplest way would be to keep your local data in an array. You can get the entire array as a json string by using the array.asjson expression. Send that to the server for storage.

    Retrieve the array.asjson from the server, and use the array load action to get it back into an array, to append and modify as you wish.

    There's no reason you need to convert the array into key:value pairs unless I'm totally missing something, like you needing to modify or access it with a third party program that can't handle json arrays for some reason.

    The other option would be to use the json object actions to set each path, object, and value, then send json.tocompactstring to the server. Then you can retrieve it and use the json parse action to load it up and be able to modify it again.

    I'd think the array method is cleaner/easier though.

    Edit: I can put together an example using local storage as the "server" later if you need.

    Hmm, I think I see what you mean. So the array will be 2D; X say would be an entire order. Then each cell in Y is one of the pieces of the order (sender, ID, description, etc...)? I just need to memorize which cell handles which piece of data?

  • Right, because an array is just a set of values with no object names, you'll need to create object names manually with the json actions manually.

    Although normally you would want to send an array as an array, and object/value pairs as is.

    Is there any reason you need to convert? Anything that can read json should also be able to read json arrays.

    Or I'm still misunderstanding.

    Oh, I don't need to convert. Basically I am trying to create this data structure in JSON:

    Orders:

    --Order1

    --- SenderID

    --- Description

    --- ID

    --Order2

    ---SenderID

    ---Description

    ---ID

    --Order3

    ---SenderID

    ---Description

    ---ID

    User logs in, sends an order and it gets added to that list on the server. Then when the other user logs in, they pull the information and get that list and I parse it to display it in a better way.

    I don't know how to get that kind of result using the JSON object or the Array object personally. I am using the PlayFab plugin which forces me to get all data currently available. Then append the order being sent. Then upload the entire thing (old + new).

    This data isn't global, it is stored per user.

  • If you don't want to use a Json array, then you can manually create keys with the JSON object actions set path, set object, and set value actions. Then the tobeautifiedstring or the tocompactstring expressions will return your json as a string you can send.

    Oh, sorry I think I misspoke. It isn't about what I want. I just don't see how it can be done. Since in my mind the array doesn't take a "key" just the value". So I wasn't sure how to set it up the key/value way so when I am reading back the JSON on the other side I could extract what I want.

  • The array expression Array.AsJSON will give you the array as a string in JSON format.

    I'm not familiar with uploading to a server. Depends what kind of server you are using. If the array isn't too large I imagine you could use a POST link to a php page with AJAX object, and the server can save it to a mysql db.

    Or if you're using something like firebase the plugin can probably send data directly.

    So let me see if I understand correctly, what you're saying is that I should have an Array object, inside that object I'd add my strings (the 4 of them) and then choose the Array.AsJSON and then send it over (I'll be using PlayFab so I am using its plugin for the upload)?

    If that is the case, that would not allow me to create the strings in a "key:value" format from what I understand.

    I'd like the JSON to be structured in a way that I can simply say:

    { orders [ sender: "senderID", description: "this is some order that has some long text description", orderID: 2, recipient: "recipientID" ] }

    So when I receive such a string from client1 on client2 I'd be able to take the data and display it to client2 the way I want.

    Does that make sense?

  • Hey all,

    So I am trying to create this ordering system. Let's say I have 4 textboxes; sender, description, ID and recipient. The first and last one are a random string of characters. Description is a long body of text. Order is just a number (int to be exact).

    However, each user in the game will have a bunch of orders and I need to store that in an array.

    What I want to know is:

    1- How do I turn the values in the 4 textboxes into a JSON (tried to look for it but seems all info is about parsing from not converting to JSON)?

    2- Then how do I add that to an "Orders JSON array" (not sure how that is done) to write it to a server?

    Any ideas how I can achieve this?

    Tagged:

  • I meant a string of text, which is a list (comma-separated) of enemy types.

    Oh, I see. I get what you mean. Yeah, that works Really well if "find()" would just simply find what I want. That is actually great. I didn't know I can do that.

    Thanks.

  • I would probably use a pair of text instance variables, for example:

    Type="F2" (this enemy type)

    EnemyList="F1,F4,F5" (what enemies are hostile to this one)

    On collision with another enemy check if that's other enemy type is in the list using find(ThisEnemy.EnemyList, OtherEnemy.type) expression.

    Note, that this expression only works if you have less than 10 enemy types. Also, you might want to create a family and define these variables on the family.

    Huh, I can use lists as instanced variables on objects? How can I do that?

  • Hello everyone,

    In my game I have multiple factions. And they basically have some friendships and hostileships.

    So basically enemies are like this:

    F1 > F4

    F2 > F3

    F4 > F1 and F3

    F3 > Everyone.

    Now in my setup, I have an object (the actual enemy sprite) and a hidden "range" sprite as child that I create at runtime so can't pre-setup it. When an object enters range, I'd like to detect which faction it is + which faction I belong to and see if it matches an enemy.

    The only way I can think of this happening is to have an "id" for each faction and then have variables like "enemy1, enemy2, enemy3, enemy4" and a "selfID" in the range object. Upon collision I compare if selfID is "F1" then ignore everyone but F4 from enemy1, enemy2, enemy3 and enemy4.

    But I feel this method is very crude and will end up breaking soon. Any ideas how I can tackle this so I can detect which kind of object entered and how I deal with it?

    Tagged:

  • Bump, still looking for a solution.

  • Hey guys,

    is there some simple way how to make my "player" sprite change weapon type after hitting certain threshold ? For example when i hit "Score" = 10,000, it changes my weapon to stronger version. Then when i drop under 10,000, it switches to previous version.

    Thanks.

    One way to go about this is to have a group in an event sheet say "Strong Gun" group and "Weak Gun" group. Then have a global variable (if score isn't level based and is something more global to the game and is carried from one level to another) called score.

    Now let's say your score increases if an enemy dies, so your code would look like this:

    Event: On Enemy Destroyed -> Add 1 to Score.

    SubEvent: Score >= 10,000 -> Group "Strong Gun" activated

    -> Group "Weak Gun" deactivated.

    Same thing would happen for the event when you lose score. In Strong Gun you have your strong gun logic and in Weak Gun you have your weak gun logic.

  • Hey all,

    I have a minimap that you can bring up in the game if you press "M". It isn't an interactive map (i.e. it just displays the layout of the current level you're in and that is that, no unit movement or that sort). However, when you are fresh into the level the minimap has fog of war (i.e. completely dark and you can't see the level itself) and as you move around the dark areas get revealed.

    For the minimap I am using one of the methods I found searching these forums. This is my code:

    https://i.imgur.com/GxrQB4I.png

    Right now I have it where I manually place black sprites around the level with size and location I want them to appear on the minimap. Unfortunately no matter how big and "encompassing" I make the sprites there are still seams and areas that don't get covered fully on the minimap despite these areas are completely covered in the level with the black sprites.

    This is the result I get:

    https://i.imgur.com/MccLXMR.png

    As you can see in the minimap (the small picture in the middle of the screen that has lots of black on it) still has seams and some areas that are displayed (walls at the bottom for example) that aren't covered. Yet in the layout I have the black sprites (that spawn their counterpart on the minimap) covering that entire place.

    Any ideas what is wrong? Any ideas what can I do to cover the minimap completely with these black sprites to simulate fog of war? Or maybe anyone has a better idea how to implement this mechanic?

    Thanks

  • You need to set both Scale Rate and Parallax to 0% for GUI layer.

    They are both set to 0, still can't see the GUI sprite at all.

    EDIT: I found a way that fixed it; instead of zooming the layout, I just changed the viewport size to something very small and that did the trick. I can now see my GUI just fine.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think I am missing something, I have this event:

    On Start of Layout -> Set Layout Scale to 7.

    This is because I am using a 16x16 sprites and otherwise the "camera" is very zoomed out.

    The issue here is that my GUI layer (layer with parallax set to 0, 0) doesn't show AT ALL. It is visible, sprites are set visible, everything is fine. If I remove the scale, I can see everything in the GUI layer. If I add the scale, this happens. Am I "zooming the camera" wrong? Or is there a way to display the GUI properly when scaling the layout?

    Thanks.

  • It seems this question has already been asked!

    Really? Could you link the question and answer because my searches yielded nothing like what I want to do.

    Note I am not looking to compare between two tiles and find them equal or not. I am also not looking for how to compare between two arrays.

    My question is how to save data from tiles in a non-error prone way that I can compare with data pulled from a different source (not tiles but actually simple sprites) and do this in an easy and non-error prone way.