How do I Check for possible combinations (learning arrays)

0 favourites
  • 3 posts
From the Asset Store
Over 2700 files with all the colour combinations from a 15 colours palette!
  • Greetings, I've tried to look this up and was pointed to the JSON plugin, but I'm having a bit of a problem comprehending how I want to use all this.

    Basically, my inventory screen allows the items to be dragged and dropped, right now I have one Item object and then it has an instance variable to tell it what item it is.

    Now I can do the basic programming for each object, i.e. when candle hits sword it becomes a fire sword. (when object 1=2 destroy and create object 3) and that works. What I need help with is how I want to set up my arrays. I'm assuming I should use a JSON file or WebStorage and I've read the book about them but am still confused.

    So here's the stats I'm storing Item Number, Item Name (Which is how it pulls up the animation as well), HP+, Move speed+, Damage+ , Defense+ and also In Inventory (to populate the inventory list). Then I also need to store what the item is combining with (I.e 1+2=3) Then I also need to store any class changes that this item makes when attaching to a character with a previous class (I.e Sword + Worker = Soldier, Bounty + Worker = Mercenary)

    So here's where I'm confused, How do I store that this item mixed with another item equals the third item? Like I set a new object in the Candle object called mix, the item i want it to mix with is ID 1, so I'd assume I set 1 as a variable (Set 1 at current@ "FireSword") then I'm drawing a blank. I know when those two items touch I want to check this database at the position of MIX... (While writing this I was just thinking maybe I should pull the Mixing out and make it it's own thing, then I can be like, 0 and 1 make 2? I don't ever have to save these combinations outside of a play game so should I even be using JSON? The only stats I'm saving as #PC (four playable characters at a time) their race and their class and their current item (only one item at a time)

    IDK I'm getting really confused and I think I'm just over thinking this.

    So yeah that's the main question, then of coarse am I using my arrays correctly and am I using the right arrays? Right now all my races are in a single array with X the name, Y the base HP and Z the base move speed, and that works well. I realize I only really need to save my one array for the characters, and am still looking into the best way to do that as well so any pointing me in the right direction for a small mobile game would be awesome.

    Anyways thank you for any response introspect or tutorial you could point me in the direction of. Basically it's a tactics game with a alchemy type leveling system.

  • You just want a way to lookup/store stats for various objects. There are many ways you can do that.

    * One is to use a json string with a json plugin. I haven't really used it yet but it's topic should have some info on it's use.

    * Another is to use an array for it. The idea you'd set the size to (number of items, number of properties per item, 1). At the start of layout you'd setup the array and later access properties with Array.At( item id, property) where property is 0 for name, 1 for HP+, ...etc. It can be tedious to populate one value at a time so you could parse a text file or make an array editor to help populate the array, and then just load into the array the array saved as a json string with Array.AsJSON. Note: for a json string to be loadable by the array it needs to have the same format.

    Here's a topic with some ideas to make populating the array less tedious:

    * A third way would be to use sprites with instance variables. Each sprite would be for a different item type. You either could add an id variable to help pick the right one or carefully keep track of the order you created them so you could later pick them with the "pick nth instance" condition. The drawback of this is you may need some more events for picking the right type.

    For mixing it would probably be easiest to just take two items and make a third. To do it i'd just use events to do it. I suppose you could also use a array of size (number of item types, number of item types, 1) to do a table lookup of item combinations, but that sounds like an overkill especially since most objects don't combine.

    For saving you can use webstorage to save a key with Array.AsJSON which is a JSONized string of the array. If you want to save multiple different arrays you can either use more keys or make an array that you set with .asJSON strings. And just as a note almost every object has the .asJSON expression as well as an action to load it, which makes it very useful for saving or loading.


    Overall I'd first just work everything out on paper what you want your system to do in exact detail with no worrying about if you'll use arrays, JSON or whatever. Basically the "what it should do", not "how it should do it". I do it all the time and I'm not very productive without some paper to work stuff out on. Like you I have most of an idea of what it should do, but don't have a lot of details ironed out. As you get better you can do more of it in your head. Event and code are just obscure what you want your stuff to do.


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you this helped a lot

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)