Mallets's Forum Posts

  • OK, that should be good to go, but I now think the true problem lies with importing the dictionary from a JSON string. I'm having trouble successfully loading the dictionary. As other threads have concluded, "Load from JSON string" requires double quotes.

    This topic in particular:

    The dictionary string is currently entered like this (this is exactly how it is written into the dialogue box for "Parameters for dictLevelNames: Load")

    "

    {""c2dictionary"":true,""data"":

    {

    ""0"":""zero"",

    ""1"":""one"",

    ""2"":""Tower",

    ""3"":""Cave""

    }

    }

    "

    but when I check the dictionary in Debug, it still shows as having 0 keys and being empty.

  • So I have a dictionary for each level and the level's name. For example, key 0 has a value of "Jungle," key 1 has a value of "Castle," etc. I want to display both of these things in a textbox on-screen, so I use this:

    (LevelNumber is a global variable)

    For textbox, set text to:

    "Level" & LevelNumber & "-" & dictLevels.Get("LevelNumber")

    This works fine except that the "Get" portion just returns 0 (because there is no key with the name "LevelNumber," I understand this part). I want the "Get" value to choose the value for the key that is currently equal to the global variable LevelNumber, but because the key is a string, I'm having trouble figuring out if there is a way using str() or int() to get this done.

    Long story short, when it's Level 3, for example, the global var "LevelNumber" will always be 3, and I want the text to "Get" the value for Key entry #3 and display that too.

    Thank you!

  • The audio plugin doesn't seem to have any way to return filenames (according to the manual page). Here's what I'm working with:

    When "On 'tracks' ended" is triggered, I want to prevent the same song from playing twice in a row. Ideally I want it to call a function like so:

    [quote:3qb4ll9b]On "tracks" ended:

    --Call function "AudioShuffle"

    --Set Parameter 0 to "(name of audio track that triggered this call)"

    On Function "AudioShuffle"

    If Param(0) and audio are equal, call the function again.

    Else, play (choose(track1,track2,etc))

    Yes, you could do this in a dictionary or array as well (toggle from 0 to 1 for "chosen track" to stop it from repeating), but I would be surprised if there were not a way to do this as the events currently are. Thank you!

  • I believe the 'system trigger once' is causing your problem in the 'for each' loop. I'm thinking that will run once at the beginning of the layout and never run again because of the 'trigger once'.

    ...

    Also, in the function, you don't pick any of the enemies so it most likely will pick all of them. So each time one enemy is supposed to fire all of them will. (Pass the UID of the enemy as a parameter of the function then 'pick by ID' as the first sub-event)

    I did indeed condense those two events, but "trigger once" must be present or else when the angle of motion is picked for each instance of the enemy, it's picked every tick (the enemy sort of vibrates in place when this happens). I made that its own sub-event, though.

    As for the function part, I'm not great at intuiting function parameters, so I may have done this incorrectly. Calling the function now looks like this:

    Call function "8DirShot" (sEnemyFlyer.UID) . When the function "8DirShot" is called, Parameter 0 is (sEnemyFlyer.UID).

    The conditions when the function is called are now set to this:

    On function: "8DirShot"

    Pick sEnemyFlyer where sEnemyFlyer.UID = Function.param(0)

    For "" from 1 to 8:

    Is this closer to what you meant with your suggestions? And yes, timers are a wonderful thing, and I'm combing through and trying to replace "wait" with timers wherever possible. Thank you so much for all the help so far.

  • Greetings all,

    I'm having a bit of trouble when using an enemy spawn sprite to spawn multiple instances of the same enemy. As each one is spawned every few seconds, I want each one to behave independently. choosing its own direction and amount of time to wait. I've checked through many existing topics on this forum already and have attempted those solutions, but still can't get it quite right.

    The code in question involves these Spawn sprites and these sEnemyFlyer sprites in the code below. The first small bit is the code for the spawner to spawn the sEnemyFlyer enemy. The larger bit below the black line is the AI that each sEnemyFlyer should adopt and use.

    Here's what I would expect to happen:

    1) As each Flyer is created from the spawned, it first checks the "On created > sEnemyFlyer" Event, then does all the actions in that event including settings its own instance variable for "AI" to 0.

    2) When that instance of the Flyer enemy sets its AI to 0, it then trigger the next event once, choosing a direction, waiting a random amount of time, then switching to AI =1

    3) After doing all the actions when AI = 1, it should switch back to AI = 0, resetting the animation and starting over.

    The problem here is that none of the enemies created by the spawner behave correctly: they don't appear to inherit the "On created" actions, and only travel at 0 degrees at their Bullet.Speed value, ignoring the entire AI loop. The only case where this enemy almost works is when an sEnemyFlyer is already present on the layout at the start. In other words, the only one not spawned from the spawner sprite.

    I would tend to think this is an issue of picking combined with the "For each" loop, but no matter how I configure it, I can't seem to get these enemies behaving properly and independently. If you know of any solutions, please share them. Thank you for taking the time to read my question!

  • Hello all,

    We all know that the best practice for organizing a project is through folders and sub-folders, categorizing project objects as neatly as possible. I'm currently working with a project that has several hundred sprites within 15-20 different folders. Every time there is a new sprite that needs to be moved to a folder, I have to drag it upwards to find the correct folder. After dropping, affected folders and sub-folders expand, cluttering up the view. Furthermore, you can only drag-and-drop one object at a time, and there is no way to shift+click to select multiple objects at once.

    This makes dragging sprites to the correct folder quite unpleasant because you can't quickly identify the correct folder by leaving it as the only expanded one, and increases the distance and time taken to drag a sprite upwards through the projects tab. The most obvious solution here is to always create objects in the correct folder to start with, but I'm collaborating with others and it's not always feasible to do this.

    I don't know if any sort of plug-in exists to improve the Projects tab functionality, but I would love to hear your thoughts on whether you have had a similar issue in your projects.

  • Would this work even when I have multiples of each? For example, 10 bushes, 10 trees, and 10 flowers?

  • Hello all!

    I'm trying to condense my code and make it as clean as possible.

    I currently have three different objects that display recoil/shaking when shot by the player's bullets. Instead of having three events each with the same set of actions (but each changed to 1 of the 3 objects), there must be a way of condensing it (into a function?). I did try putting the 3 objects into a family and having the function affect the family, but it turns out this affects every member of that family. Here's a more concrete example with sine behavior providing recoil (could be done with shake or other behaviors):

    When sPlayerBullet collides with sTree:

    --destroy sPlayerBullet

    --Store sTree's X and Y positions in instance variables

    --set sTree sine cycle position to 0

    --set sTree sine inactive

    --set sTree sine active

    --set sTree sine magnitude to 3

    --set sTree sine period to 0.2

    --set sTree sine movement to horizontal

    --wait X seconds

    --Set sTree sine inactive

    --Restore sTree to the stored X and Y positions

    The same event is copy/pasted for sFlower and sBush, (but with the correct object) so it's the same set of code 3 times in a row. Is there a way that I can have this set of actions only once in the event sheet for efficiency? Even using function parameters, it seems that I would still have to copy paste the code 3 times, and a simple "or" condition would still have to specify which objects to act on. But ideally, it would look like this:

    When sPlayerBullet collides with (sTree, sBush, or sFlower)

    --Call function "Recoil"

    and then:

    On function "recoil"

    --destroy sPlayerBullet

    --Store tree, bush or flower x and y positions in instances variables

    --(same as above example)

    --restore tree, bush or flower to x and y positions

    Thank you!

  • I think a lot of us are really great at using C2, but I'm sure many people have interesting tricks and tips they use during coding that can make our lives easier. Let's share some of those tips!

      Set up a textbox with debug information, such as your character's speed, vectors, acceleration, etc. Put it on a 0,0 parallax UI layer so you can see it at all times. On player death, set up a textbox to appear saying "killed by X." This has helped me SO many times because it points you directly to the event on the event sheet that is related to the player death. Useful when there are traps in your levels. The "MoveTo" plugin lets you smoothly move any sprite over a distance or toward an object without changing its position every tick (like you would do without the plugin). Make your playable character's stats variables. For example, make his speed "PlayerMaxSpeed," then define this variable in the event sheet. If you ever need to change his speed or let the player upgrade, you won't have to go edit the event sheet line by line. Good for gravity, max speed, acceleration, etc. An easy pause screen event: On press (pause button) -> set time scale = 1-timescale. If it is 1, it'll go to 0 (paused). If it's 0 (paused) it'll go back to 1!
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • As far as I know it have always been like that in C2 and from what I recall have been wanted by users for a very long time. So I wouldn't count of it getting into C2, maybe C3.

    The best thing to do, I think, is to "think before doing" not meant in a negative way, but when you plan a project and you for instant think its time to add enemies. Then the first thing you do is to think project organisation, so you create the folder structure you need, then you create the enemy objects and what you need for them to work (sprites, text etc) and then when you think you are done with them, you drag them to enemy folder. And then you can start with the next thing. If you need to add a lot of the same type of objects, for instant sprites, then you drag the first sprite to the folder and clone it rather than add them through the menu, then it will automatically be added to the folder.

    This is the habit that I've started trying to get into. You're right about planning before acting here! I think from now on I'm going to make "dummy" sprites as the first object in each folder and then whenever I want to make a new object I'll be forced to clone from the dummy directly into an existing folder, rather than uncategorized and piling up at the bottom of the projects tab :-p

  • Hello all,

    I have nothing but praise for Construct 2, but I'm wondering if anyone else has had an experience similar to mine concerning the projects tab.

    When I'm organizing items into folders or categories, I instinctively want to CTRL + click in order to select multiple items, especially if I'm organizing in folders I've just made (Level 3, Boss #2, etc). I understand if the program's coding doesn't allow for multiple selection. But the projects tab doesn't spread horizontally in any of its available views, so I'm dragging one item at a time to the desired folder, waiting for the projects tab to pan up and down each time as I do, since its height is limited to the height of your monitor's resolution.

    I haven't come across any sort of plugin that would allow for this sort of feature, but when a project gets a little complicated with so many different objects, trying to navigate the projects tab can be a little confusing to me. I suppose the best options is to simply collapse all folders you're not working with so that you can see most or all of the projects tab at any time.

    Anyone else also have this experience? If there's no solution currently in place, would anyone else feel that it would make a nice addition to C3?

  • Wouldn't it be simpler to keep the origin as the center and have another sprite for the death animation?

    Or leave it as is and when you change to the death animation just move the sprite?

    You can use a little math to rotate a sprite around any point if you wish to do that instead.global number centerx= 100

    global number centery= 100

    global number ang= 10

    every tick

    --- sprite: rotate ang degrees clockwise

    ---- sprite: set position to ( (self.x-centerx)*cos(ang)-(self.y-centery)*sin(ang)+centerx, (self.x-centerx)*sin(ang)+(self.y-centery)*cos(ang)+centery )

    Oh, wow. This would do it, huh? I never would have figured this out in a million years, so thank you so much for the explanation!!

  • OR blocks actually pick instances that met any of the conditions. The | operator is simply a logical OR that returns 0 or 1, based on if either operand was true (nonzero). So if you have "health = 7|8", then 7|8 is evaluated as "true OR true", which results in true, which C2 represents as 1, so it's the same as saying "health = 1" which probably wasn't what you intended!

    Wow! This is definitely not what I intended. It's great to have such a welcoming community to get help with this stuff because machine logic just baffles me :-p

  • More than one origin point, huh? Is this different than right clicking in the image points dialogue box and choosing "add image point?"

    I knew you could have multiple image points but I only ever had one origin point. For example, if I choose to do "every tick, rotate BossSprite by 12 pixels," it automatically chooses the origin (or perhaps it just chooses the 0th image point?) I guess my question here, then, is that since there's no way to use the "rotate clockwise" action to say "every tick, rotate by 12 pixels based on image point 1," that there must be another way to do it.

    I'm using the invisible block idea I mentioned above, and while it works, I'm sure there's a simpler way.

  • Hi all, thanks for reading!

    I have a boss sprite with an origin that's "bottom," and for its death animation only, I want it to rotate as if its origin was in its exact center. This way, it doesn't look like it's flipping out wildly in large circles, and instead should rotate smoothly in place.

    My thoughts on this are:

    • Create an invisible block that spawns when the boss dies. Pin the boss to the block upon death and just have the block rotate in place.
    • Somehow change the sprite origin with events, which I don't believe can be done.
    • Some other action commands that can achieve the same goal, such as "rotate around point X"