tarek2's Recent Forum Activity

  • > How does it check which one we passed as a Parameter

    Internally this would be done with a map lookup, which is very fast (and faster than a sequence of if-else-ifs).

    Hoo Grate! that sounds really good Thanks

  • One Question that makes me Wonder

    when you >>>>Call function from "color" map with <string>

    and we have the Function with 3 Options

    On function ColorCall

    -> Map "color" string "Red" to RedFunction

    -> Map "color" string "Green" to GreenFunction

    -> Map "color" string "Blue" to BlueFunction

    How does it check which one we passed as a Parameter, Does it work Like "Else" or it just calls directly the one Selected one from the Parameter String? so basically its this method better and faster than do it in the old fashion way with Else, Else like I did on my previous Pictures

  • > what would be the benefit of having it be it's own block?

    I don´t see why such a map would need to be created during runtime with individual actions, rather than just beeing there.

    I think the best Idea is to support both ways if it's possible as some people would like to create at Run Time and some before RunTime I think, I can see the benefits through creating before RunTime if you have heavy Loops & Events Running at the start of layout and you prefer to avoid extra Events & Actions

  • What are you doing in those events? Sometimes you can eliminate the redundancy by using what you're passing as Enemy_type in an expression. For example you could look up a dictionary key, create an object by name, etc...

    Probably it wasn't a good example calling it only at the Start of Layout but Here is a better example to help illustrate what I was referring to, not sure if is the best example but I think you can get an idea, I tried to make it simple so it doesn't get messy with to much code, I just put a random example. so basically is just to illustrate that we call the Functions targetting directly the Enemy Type without checking every time "Elses" I hope it makes sense. but this is just one of many useful things that you can do by calling Functions by String.

    https://www.dropbox.com/s/ndkhuay0rgdsi79/New%20Functions.capx?dl=0

    ==================================================

    I think it should be possible to support this without using expressions for function names, though. The equivalent in a programming language would be a map or a switch-case of a string to a function call. Construct doesn't yet have any equivalent, but we could add one. It could work something like this. Suppose you have "Call function <string>" which can call one of "Red", "Green" or "Blue". That could be replicated with a "function map" feature along the lines of this:

    + On start of layout

    -> Create function map "color"

    -> Map "color" string "Red" to RedFunction

    -> Map "color" string "Green" to GreenFunction

    -> Map "color" string "Blue" to BlueFunction

    Note that RedFunction, GreenFunction and BlueFunction refer to built-in functions, and aren't strings (this would be some kind of new function-picker parameter). Then instead of "Call function <string>", you could use:

    -> Call function from "color" map with <string>

    That sounds like an awesome Idea looks like is exactly what we need

    Thank you for looking into it

  • It's impossible to get all the benefits of functions if you can call them by name, since it can't display the correct parameters and validate them. Instead, you can pass the dynamic part of the function name as a parameter instead.

    Thanks, I see what you mean

    I tried the way you advised but I still get the same Results I have to through all the "Else" Checking which is that what I'm trying to avoid when using Functions,

    Example:

    I tried By Passing the UID through a Parameter and then Pick the Object and check the Variable "Enemy_Type" directly from the Object

    Or by Passing the "Enemy_Type" Variable as a Parameter and check the results inside the Functions the same as the First Method.

    But Both are exactly the same thing they have to go through the process of all the "Else" checking which can be really Performance Impact when you have many Enemies and many Different Variables to check very often, ending up with long lists of "elses" is there any way to avoid this like we could do with the old Functions? or is any Plans to add it on the Future? as this feature is really important

    Thanks for your Time

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • One of the Most Powerful things that I liked about the Old Functions is that when you have to check a Condition that has many "Else" I could just then replace it by calling directly the Function to avoid many Else checks unnecessary especially when it has to check it very often, I tried to do the same with the New Functions but I couldn't, is this feature removed? will it be in the future? as it's very useful

    Thanks

    Here is what I mean:

    On here I have to check which type of Enemy is and depends on which enemy is he has to do different things, I haven't done any actions but you can get the idea

    When the Else becomes to many like on this Picture

    I just Replace it by this

  • Just saw what you said about pushing the value in the front of the array instead of inserting one. I also moved the events where the master array is setting its values to the other arrays as json into its own function called "compileArrays". It's getting me a little closer, but now when I load up the project, the scale is off and some of the objects are mismatched.

    Hard to know without seeing your whole Project see if this can help if you do everything the same as this example it should work if it doesn't work it must be somewhere on your project interfering with your Events

    https://www.dropbox.com/s/g8f4rni4bcul9sx/Save%20%26%20Load%20%20Custome%20Levels.capx?dl=0

    Apart from that, a few Tips that is nothing to do with your Last Problem is just to let you know:

    -When you set Array size (W = 0) you don't need to clear the Array Before as it becomes Empty anyway

    -When you try to Load an Array from Json you don't need to (Clear or Set Size) before that as it already loads the correct size from the JSON File

    -You can use Families also

  • I can open your capx as it uses 3 Plugins, but looking at your Picture of the Events this is what I see

    On your Function "On Save" you are downloading the JSON Array "edit_objectdata_AMASTER" before you save all your Info of the Objects of the Level, The Array "edit_objectdata_AMASTER" download AsJson it should be at the last Event after you save all the Info on it.

    Also on the same Function "On Save"

    Make sure you set the size of the Arrays to = 0 before you use the Expression Insert so you don't create extra Empty Cells on the Arrays

    Example:

    Before the Loop set Array Size

    W = 0

    H = 1

    D = 1

    Then use the Loops to save the data example to save the coins:

    -set Array Size

    W = 0

    H = 1

    D = 1

    -Then For Each Coin: Array Coins Push Front Coin.AsJSON

    Note: The Array Sizes you set them Once only and outside the Loops, probably at the Beginning of the Function on Event 78, set all your Array Sizes there

    Also, you don't need to clear the Arrays if you set the Size (W = 0)

    =--------------------------

    Now if you Did what I Wrote above you should have each Array as 1D = 1 Dimensional Array

    so you need to change the Events On Function "BuildLevel" Especificly the Loops that you use on the Array

    -Instead of using Array For Each XYZ you need to replace it by Array For Each X Element

  • If its a new Picking you need to start from scratch always Comparing Variables etc.... But if the Picking didn't change you could save the UID of the Sprite so you can keep Picking it whenever you need directly

    Example:

    Have a look at on "Key Down Pressed" I Pick directly the Player I need By UID without the Need to loop again throughout all the Players to check who is matching the condition as opposite than we do on the Function "Pick_Player"

    Also, you don't need that many Functions as Newt mentioned

    https://www.dropbox.com/s/3jjshxd3bjkq98q/Picking.capx?dl=0

  • Awesome! Thanks for the Key I will give it a go as sooner I have some Time

    Congrats For your First Release Game and Good luck with the Sells

    I used This Key:

    VMTAF-6AFW2-7YZRX

  • The Instance Variable has to be (Type = Txt) to be used with a string, at the moment you have the Instance Variable as = Number,

    However, you can still use it with an Instance variable = Number as longs you convert it to a Number with the Expression "Int"

    Example:

    int(tokenat(text, 0, "|"))

    The only problem with this is that it will round the Number and you will lose the (.4)

    Not sure why Globals can use it and Instances Variables Not

  • Update:

    Finally, I saw some Light and understood why is working the (Tilemap.TileToPositionX(loopindex("Y")))

    It's because your Map it's perfectly aligned on the Grid and the Origin Point of the TileMap (0,0) also the Tiles are symmetric 64x64

    So even that the true it Loops Retrieving the X-Coordinates Of the Tiles using the Index of Loopindex("Y") but because the Tiles are symmetric and Both Indexes start at 32

    Example:

    (Tilemap.TileToPositionX(loopindex("Y=0"))) >>>>> 32px at the X Cordinates

    (Tilemap.TileToPositionX(loopindex("Y=1"))) >>>>> 96px at the X Cordinates

    (Tilemap.TileToPositionX(loopindex("Y=2"))) >>>>> 160px at the X Cordinates

    (Tilemap.TileToPositionX(loopindex("Y=3"))) >>>>> 224px at the X Cordinates

    Etc.....

    Will be the same as if you used TileToPositionY

    (Tilemap.TileToPositionY(loopindex("Y=0"))) >>>>> 32px at the Y Cordinates

    (Tilemap.TileToPositionY(loopindex("Y=1"))) >>>>> 96px at the Y Cordinates

    (Tilemap.TileToPositionY(loopindex("Y=2"))) >>>>> 160px at the Y Cordinates

    (Tilemap.TileToPositionY(loopindex("Y=3"))) >>>>> 224px at the Y Cordinates

    Etc...

    This Time you been Lucky as the TileMap was aligned to the Grid :)

    But if the TileMap wasn't Aligned to the Grid Example:

    TileMap Position at (250, 92)

    and the First Tile Coordinates will be at (X=282, Y=124)

    So if you use the same System as you did to Retrieve the Y-Coordinates

    (Tilemap.TileToPositionX(loopindex("Y=0"))) >>>>> 282 px at the X Cordinates (Wrong)

    Vs

    (Tilemap.TileToPositionY(loopindex("Y=0"))) >>>>> 124 px at the Y Cordinates (Correct)

    as you can see the Results can be very very wrong, Conclusion the sooner you start using the correct expressions the fewer mistakes and headache you will have in the future, even if it did work this Time swapping the Loopindexs is not guarantee it will work next Time, but if you use always the correct Expressions you will have peace

tarek2's avatar

tarek2

Early Adopter

Member since 26 Jan, 2016

Twitter
tarek2 has 12 followers

Trophy Case

  • 8-Year Club
  • Forum Contributor Made 100 posts in the forums
  • Forum Patron Made 500 posts in the forums
  • Forum Hero Made 1,000 posts in the forums
  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • x5
    Great Comment One of your comments gets 3 upvotes
  • Email Verified

Progress

15/44
How to earn trophies