trashgg's Recent Forum Activity

  • I tried to copy your code and see what would happen.

    Aside from a few variations and a couple of additions to make things clearer, the code is the same. Instead of tanks coming from you right I have ships coming down from the top in a vertical layout. Also their spawn positions are not random like yours.

    The code worked exactly as intended. The original enemy sprite has a blue tint so I let the ships spawned on pattern = 0 with the original coloring but gave ships spawned on pattern = 1 a red tint and the ones spawned on pattern = 2 a green tint to clearly differentiate them. They never mixed up. There were either blue enemies, red enemies or green enemies on the screen. For pattern 0 and 1 it spawns 4 ships in a wave and for pattern 2 there are 8 ships. Everything seems to work fine so your problem might be in some other detail.

    I would like to give you the .capx file but I can't post links until I have 500 reputation. If you are interested, message me with an email address.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Dug out, tidied up and commented. This might be a terrible way of doing it because of looping through the code until it finds the correct member of the family but in my tests it appears to work quite well and saves quite a lot of code.

    Now that's creative . Thanks for the idea. I'll have to try each solution and see which works best for me.

  • The plugin being made by rexrainbow you can safely assume it will never break, and even if it does, it'll get fixed in no time. So no worry there.

    That's good to know. I should give it a try. Thanks again.

  • 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.

  • 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.
trashgg's avatar

trashgg

Member since 16 Apr, 2014

None one is following trashgg yet!

Trophy Case

  • 10-Year Club
  • Email Verified

Progress

11/44
How to earn trophies