trashgg's Forum Posts

  • The might help you.

    There are however some tricks you could do if you prefer the vanilla way. You could create a function named "CreateShip" that receive a string parameter, and using a long list of "if else if...", create the correct ship, and set the return value to the newly created ship. Whenever you want to create a ship, use that function, and use a "Pick by UID" on the ShipFamily with the return value to change its family instance variables.

    I once did an of something similar.

    And as for the "On created" issue, the trigger is indeed called before the remaining actions. This is by design, so you will have to take that into account when you use this event.

    I see, thank you. It seems that's what I will end up with, a long list of ifs. The problem is that I intend to have tens of models but I have split them into categories and each sprite will represent a category and hold every model of that category as a separate animation. We'll see if that strains memory too much. The plugin sounds good but I'm not fully aware of what using one implies. If the plugin stops being updated along with Construct, do I run the risk of it not being compatible with the latest versions at some point?

  • Could you take a screenshot of your script and post it here? Someone could find the problem faster that way.

    For now I understand that you are trying to spawn 1 random enemy at a time and after the first one is destroyed you get 2 random enemies at a time but I can't see the problem in your script. Is any of the variables a Local Variable?

  • Hello

    I'm working on a space invader game and I've ran into a couple of problems while trying to spawn ships and fill in values for their variables depending on the model. Here's a bit from my script.

    I have to spawn multiple models of ships, depending on what the player chooses but for now it's just one. I've set some commands to assign values to some of the ship's variables but only a few essential ones. The rest I want to set using the Ships | On Created event to save script but I've only added a few for now. Note that FighterShip is part of the Ships group.

    The problem is that the commands of the On Created event seem to trigger before the commands on the first event. Either that or the commands on the first event only trigger a frame after FighterShip is spawned. To test this I put in the NumTest command and event. In debugging I saw that even though NumTest had been set to 1 the ship's text variable "HeavyGun" was not set to "No". I take this to mean that NumTest was not 1 at the time when On Created was triggered but only later.

    Am I missing something here? Does anyone know exactly the order by which these events run? Does spawning a sprite require 1 frame before it can be accessed by Events and Commands?

    My other problem is making a dynamic script for spawning multiple types of objects. I wish I had a command where I could type in the name of the object to be spawned or put in a variable but there's clearly no such thing. Instead I have to do a separate event for each type of ship. If the variable that determines the ship model is FighterShip, spawn FighterShip, if the variable is set to TraderShip, spawn a TraderShip and so on. I wish I could just have a command that says Spawn Object "ModelVariable" to replace all the ifs because there will be a lot of models.

    I tried the trick of spawning a Ships family object instead but it only chooses a random object from the family to spawn and I can't control it. I tried to have an event select one FighterShip and then spawn a Ships object but it still spawned random models, not just the FighterShip. Does anyone have a better solution than making a long list of events, one for each model?

    Any help would be greatly appreciated as I still have a lot to learn.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Probably not. For security reasons Javascript tends to limit access to various things, otherwise the web would be full of dodgy scripts which changed all sorts of things. Javascript is very sandboxed.

    I don't quite see why you'd want to. Your 5 JSON files are your games initial state, and your localstorage version is the current state of the game. Overwriting your original files sounds like a bad idea - supposing you wanted to restart the whole game, where would you get your original data from.

    More to the point, does it *matter* ? JSON files, even quite complicated ones, take up very little space compared to sound or graphics files.

    Well, at least I wasn't overlooking something. Thanks for explaining, I hadn't thought about the initial state issue so I guess I'll just continue with LocalStorage + starting JSON files.

  • Hello

    There are 5 arrays in my game, each meant to provide data for one of 5 campaigns and after the game starts they each load that data from one of 5 JSON project files. During the game the data in the arrays changes, like number of completed levels or level scores and such and ideally I would like the game to save the data in the arrays back to their respective JSON files but I have no idea how to do it.

    I've been searching the forum for an hour and since I can't find anything I will assume there's a simple catch I'm missing (again). I've managed to save the modified data from my arrays using Local Storage and then load it back up but Local Storage creates it's own files apparently and that leaves me with 5 extra JSON files that are only used on the very first run of the game. Right now it's not a big deal but it will be once I start using arrays and JSON to save levels.

    So is there a way to simply save the data from an array back to the JSON project file it was loaded from?

  • [quote:u6tr9muw]Right, I knew I was missing something simple. Thank you. However I did this and nothing's happening, my array is still empty:

    Do you mean something else by "set array to Ajax.LastData"?

    I tried it with a different array and .json file and it definitely worked. I'll figure out why the first one doesn't work. Thanks for clearing things up, now I can handle data much more efficiently.

  • In your C2 project right click on the Files folder and choose "Import file" and from here select and import your json file.

    Right, I knew I was missing something simple. Thank you. However I did this and nothing's happening, my array is still empty:

    Do you mean something else by "set array to Ajax.LastData"?

  • You need to use Ajax plugin to load up the file.

    Ajax:Request project file and then Ajax:On completed set array to Ajax.LastData

    I tried that but the only files I can choose there are .pngs. I found the folder where they are located and placed by .json file there but I still can't select it in the top-down list. Maybe I got the wrong folder. The only folder I found that contained the files in the list was Program Files\Construct 2\exporters\html5.

  • I've been searching the forums for more than an hour for a solution to this seemingly simple problem but either I wasn't able to find it or the explanations I found were too complicated for me. I am new to arrays and I would like to know how I can load the data from my menu_data.json file into my empty menu_data array. I wrote the data inside the file via notepad in the exact format that construct saves JSON files. Here's what it contains:

    {"c2array":true,"size":[6,2,1],"data":[[["PreMenu"],[0]],[["StartMenu"],[0]],[["OptionsMenu"],[1]],[["CampaignMenu"],[1]],[["LevelMenu"],[3]],[["Game"],[4]]]}[/code:3pfeiu9d]
    I just want my game to load the data into the empty array when it starts. Please note that I need pretty specific instructions, I get the array concept but I'm still fuzzy on the commands. Also, I have no idea where I should place the file so the project can load it.
  • And what do you know, 20 seconds later I have figured it out. It was my own script just doing what I had told it to do - stop playing the music as soon as the "LoadMenu" variable changes and that happens when you click one of the buttons that is supposed to load a different layout except I hadn't yet made it load the layouts. Disregard this, sorry to bother.

  • I'm building a menu and ran into a slight problem. My menu has background music that starts playing in loop when the layout is loaded but I added a click sound that plays once when you click on the menu buttons and now every time I click a button the music stops. The lick sound works fine though. I bet the issue behind this is tiny but I can't seem to find it. Any help would be appreciated.

  • I still believe that by using a container is more simple to do it, but here you go...

    Thank you. I'll have to try both versions and see how I can make use of them. As you can see I still have a lot to learn.

  • When you spawn, store the UID of the Circle in an instance variable of the Square. When you click the square, Pick the Circle by UID, and do your light-up code.

    I had already stored the UID of the spawned object but have no idea how to pick it by UID. Could you please be more specific? I'm still a bit confused by parameters.

  • I've been searching for hours for a solution to my problem but couldn't find anything. Maybe I need a more simple explanation or maybe I've just overlooked a very simple solution.

    Let's say I have several instances of a Square object in my layout and they each spawn a Circle object somewhere in a random location when the layout is loaded. Now how would I make it so every time a Square is clicked the circle it spawned will briefly light up? I know how to make the Square respond to a mouse click or mouse-over and I know how to make the Circle light up, I just don't know how to build that connection between them.