nimos100's Recent Forum Activity

  • Not sure if it will solve you problem, but it seems weird that the Collision X > 1301 is below Jack Pick nearest ..... As I assume you want to pick the nearest jack to the collisionFamily that are between these values?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • No problem

  • I downloaded your capx. And have modified it. Just so you can see how to do it.

    Personally I would consider changing the way you select spells, so you could simply left click to equip it in Q and right click to use W. But anyway, I have added comments to it, so you can see what each thing does.

    However here are some further explanation.

    1. I made a family that hold your spells, this is simply so you don't have to repeat the code as much. And to difference between the spells, I have just added a variable to the family called spell_nr. that goes from 1 to 3.

    2. I have added 3 imagepoints to the spell bar, so each spell can be matched to a imagepoint location when they are swapped. Again this is simply to reduce the amount of code needed.

    3. To the two Q and W buttons I have added a variable to hold the nr of the spell that is currently equipped. This is when it is replaced, I can return it to the spell bar, before placing the new one.

    4. The Q W where you select which spell to equip, also have a variable called Selected_spell, which hold the Spell_nr that was chosen. This is so it knows which spell it should equip.

    https://dl.dropboxusercontent.com/u/109921357/Equippind_and_Disequipping_Test.capx

  • I haven't looked at your capx, so depending on how you made it. You can for each hotkey store the spell_UID, spell name or whatever makes them unique. And simply overwrite this value, from what I understand you want it to swap, but actually you don't need to swap, but just overwrite.

    So if you have:

    Hotkey_Q = Spell_1

    Hotkey_W = Spell_2

    And want to change Hotkey_Q, it doesn't really matter what happens to the spell that is already there, so you simply.

    Set Hotkey_Q = Spell_2

    And Spell_1 automatically gets "Unequipped".

    So if you have already made it so you can equip a spell it should work fine if you overwrite them.

    If you want to make sure that the player cant equip Spell_2 two times, you can check in Hotkey_W if Hotkey_Q not equal "Spell name" then equip spell.

    And reversed for Hotkey_Q.

  • Since I just made a very simple example of a function and how to call it in another post. Ill add it here as well, as functions are actually very easy to use, the moment you get them.

    1. Add function plugin

    You first have to add the function object to your project. You find it in the list where you also add mouse, keyboard etc.

    2. Create a function

    Once the plugin is added it will be available for your whole project. To create one you add it like you would any other event. And you have 2 options to choose from:

    "On function"

    "Compare parameter"

    For now you only need "On function" and this can be compared to adding an "On mouse click" event, but instead of "On mouse click" already being added for you, you can decide what it should be called, and when to trigger it, which is done by calling it.

    So after you select the "On function" you will be able to give it a name.

    "Name" is just a reference so C2 know which function you are calling whenever you do a function call. So you can make it whatever you like.

    In the above example I want the function to give me the license plate of a car. So giving it a name of "Get car license plate" describe what the function does so I can remember it. But in theory I could have called it "Moon rising" and still make it return the license plate of a car.

    3. What a function does

    Now that you have added a function it will be empty and not very useful. To make it useful you want it to do something for you. And you can see a function like a machine you put something into it, and it does something and then it might throw something out.

    In the above example I throw in a car, and I want the function to give me the license plate of that particular car.

    Input = Car

    Output = license plate

    4. Calling a function

    A call to a function is an action, so like you would set the text of an text object, you will make the function call as an action.

    When you press "Add action" you can again select function, but this time you will have two other options "Call function" and "Set return value". Since we need to call a function you just select "Call function"

    And again It ask you for a name. Now this name need to be the name of the function you want to call. So in this case "Get car license plate". This will make C2 aware that this is the function it should look for.

    5. Parameters

    In this window you can also add parameters. Which would be the input, so in our case we want to throw in a car, since we want the license plate of a car. We need to tell the function which car we want the license plate from.

    So if you press "Add parameter" there will be added a field called "Parameter 0" These names are locked, so you can't change them. But you need to be aware of the order in which you add them. But for now since we only need 1 it doesn't matter.

    Since we want a specific license plate of a car, we need something that is unique for a car. So the UID of the car objects works very well, as its unique for any object. So we throw that into the parameter 0.

    6. Make the function do something

    So now the function call is ready and will do what it is suppose to, however since our function is empty it doesn't do anything.

    So the first thing we have to do, since a function isn't that clever even though we have already thrown it a "Car object" it still doesn't know what that parameter is for. So to make sure it knows, we add:

    "Car pick instance with UID function.param(0)"

    Since we stored the UID in parameter 0, we can also use it to select a car which match this UID. Now the function know what car we are talking about.

    7. Return value

    The same way as we added the function call, we now add an action of "Set return value", when you add it you get the possibility to set a Value. This is what will be returned when the function is done, doing what I does. In our case we want it to simply return the license plate of a car.

    Since we have already told it what car we want the license plate of. We can simply set the return value to "Car.license_plate"

    8. Using the return value

    Now that it have returned the license plate we want to use it for something. So what we can do is to check the return value and then act on it.

    In this case we want to check if the returned license plate is "12345678" and if that's the case then do something.

    That is the basic of using functions and in this example we returned a license plate, however its perfectly fine to not have a function return anything.

    When C2 reads your code and it gets to a function call, it actually jumps into that function, and will not continue reading your code, until it gets back from the function. So you could actually add everything that are in the function instead of the function call, and it would be exactly the same.

  • Here are some advise that might be useful.

    1. Clean up

    Objects that you don't need to be there from the start, by this I mean sprite objects that would be "Units", "Bullets" etc. you should destroy at the beginning of the game. This is simply to make sure that you don't have rogue objects in your program.

    2. Precise functions

    Make as small and precise functions as possible. Even though some of these functions might seem to simple for it to make much sense.

    And example of why this is a good idea. Imagine you have a "Car" and in you code you might change the speed, so you simply as you make the game, set the speed to what ever you think would be good. This would be fine until the moment you decide that it could be fun to add, if the speed gets above a certain amount that the car should start loose control. If you add it in your code you would have to change/test for it everywhere you might change speed, if you have a function you can simply add it here and update it for the whole program.

    3. Global constants

    This can be very useful for reducing spelling errors, and to quickly change things in your game. Imagine as the above example, that you have several car objects which are categorized by a type, "Cheap car", "Normal car" and "Expensive car"

    If you in your code manually add checks if ( Car.type = "Cheap car" ) and then do something, at some point you might figure out that this weren't that good, and it should instead have been something else, then instead of having to go through you whole code, you can just update 3 global variables.

    4. Use several event sheets

    Don't be afraid of using event sheets even though you might not add a lot to them. It will really help you maintain an overview of your game.

    5. Split events and functions

    Unless you are 100% sure that an event sheet should only be used one place, its always a good idea to split events and functions, even though they work on the same object. So an event sheet called "Car events" and "Car functions" would be a good idea. You can always move functions later on, but think it good practice to just get used to splitting them.

    6. Requirements and returns

    When making functions I find it very useful to add comments above them with requirements, and potential return values. This will make it very easy later on as you move along and might forget what a function actual does when you return to it.

    An example could be like this:

    7. Bug sheet

    Make an empty event sheet, that you just use for comments. You don't include it in your program. But the purpose is as you test your game and might be testing something, suddenly notice that something else is not working as intended. Then instead of fixing it straight away, you just in you "Bug event sheet" add a comment explaining what you noticed. And if possible the cause for it. Then you can always fix it later and you wont forget about it.

    8. Quick reference function sheet.

    This can be a bit time consuming but very useful. The idea is again to add an event sheet that you don't include in your program. But you simply add function calls to it, with the required amount of parameters.

    This can speed things up quite a bit as you can just copy/paste function calls from this sheet to wherever you need them, and just update the parameters, and you don't have to remember the name or how you spelled the function name etc.

    Other than that I think the other advise are good as well.

  • First of all sorry for the bad topic name not sure what to call it

    But was thinking of another feature that could be useful, as most are aware of when using lots of function, there might be calls to these all over the place.

    So a feature that could be very useful I think would be if you could right click or shift+left click a function call in your code, and jump to that function. And maybe make it so you could jump back again. Would be very useful, for me at least, I tend to expand functions over time but forget where I put them, sometimes, so it would make it a quick way to jump there. Think that would be a really nice feature.

  • I don't think there exist such place, at least not what I know of.

    But I would say that if you have done all the tutorials that comes with C2 you should have a fairly good understanding of how to do things.

    When I started I just did the first one tutorial, to just get a hang of how to navigate the program, and the rest was pretty much trial and a lot of error, and a good community always willing to help, even with very simple questions. Think that's a big help for anyone new, that they don't feel stupid for asking such questions.

    So if I were you, then I would just choose something that I thought could be fun trying to make, something very simple, and then see if there are a tutorial that uses something that might be useful for that, and then just try to make as much of the game as possible, or start a new project when you notice that you screwed something up big time. And then make use of what you just learned, and maybe add something new that you think could be fun. Then you just keep doing that until some point where you have a very good understanding of how to do the different things.

  • So I'm starting to understand arrays a bit more but still feel like a complete noob, I tried setting some text every tick to "TileProperties.At(Mouse.X,Mouse.Y)" but I am assuming that it's the wrong way as it stays at a constant "0" I'm pretty much just going by trial and error at this point xD

    Yeah that will most likely give you a 0

    The reason for this is probably because there are no data stored at the given position.

    As you move the mouse around, you constantly update where in the array you are reading data from. So if your layout is 1000x1000 pixels. And you move the mouse around you will look up data in the array based on pixels rather than tiles. This is because each tile in the tilemap is not 1x1 pixel big, but might be 32x32 or whatever you have chosen.

    If we assume that each tile is 32x32, then the array at position (0,0) would actually be all pixels from 0-31, 0-31.

    So what you have to do in order to get "TileProperties.At(Mouse.X,Mouse.Y)" to work, is to convert the mouse-position into a tile position. which is fairly easy, using the tilemap function PositionToTile(X,Y).

    So your function should look like this:

    TileProperties.At(Tilemap.PositionToTile(Mouse.X), Tilemap.PositionToTile(Mouse.Y))

  • [quote:2vimrvlb]Having multiple tilemaps like Nimos100 said is also a nice solution, as it is easier to read/write in the events maybe. I'm not sure it is best performance-wise, but as the map isn't drawn, I don't see any problem. For a debug purpose it's a lot better this way (as you showed us).

    Performance wise I think using arrays are faster, but in my game as its automatic turn based or what to call it, meaning that each time the player does something it will do a turn. So I don't have to update my tilemaps all the time. but only when something trigger some change, which would be to one tile at the time.

    Another benefit is that the player can hide and show different things, like showing the territory of the different empires, building areas and so on. Since they are separated showing and storing these information in tilemaps make it very easy to work with. So for me I don't really get a lot from using arrays over just using the tilemaps them self, as the performance is not really affected a lot by having several tilemaps.

  • What he means is that if you have a tilemap that are 20x30, so 20 tiles in X direction and 30 tiles in Y direction. Then you should make an array that are 20x30 as well, the Z value (the 5) are the one that holds the information for that tile, in his example it can hold 5 different information, if you need more you just increase it to whatever you need.

    An example:

    If the tile in your map at position (1,1) is a rock. Then the array at (1,1,0) could hold rock.

    The reason he use 5 is simply if you need a tile to store several information. So lets say that this tile also have a defence value of 2.

    Then your array would be like this:

    Array(1,1,Rock)

    Array(1,1,Defence value 2)

    So the first two numbers in the array refers to the position of a tile in your tilemap.

  • I use something similar in my game, the way i do it, is by using several tilemaps.

    So one tilemap are the terrain informations, meaning that this is where the map is actually drawn, stuff like grass, mountains, deserts, water etc.

    Next there are a tilemap that holds road, rivers etc.

    A collision tilemap that hold all informations about which tiles are impassable and how costly it is for a unit to move on a given tile.

    There are some other tilemaps as well.

    So what i can do, is simply use each tilemap to check certain things. For instant it is more costly to move in mountains than on grass. So ill check each tile during start of the game, and save these information to the collision tilemap. And then i just check for roads and if there are a road on a tile with mountain it will then use the road settings and not the mountain.

    In my game, if i render the collision map it will look like this:

    Now there are some tiles that are not added.... but the color goes from none to black, where red cost a lot, and black is impassable, such as water. So it works fine, and units prefer moving on roads, avoid mountains etc. And it gives a good amount of flexsability as you can add several different tiles on top of each other and just read the information from a given tilemap when you need it.

nimos100's avatar

nimos100

Member since 23 Sep, 2012

None one is following nimos100 yet!

Trophy Case

  • 12-Year Club
  • Coach One of your tutorials has over 1,000 readers
  • Educator One of your tutorials has over 10,000 readers
  • RTFM Read the fabulous manual
  • Email Verified

Progress

16/44
How to earn trophies