mekonbekon's Forum Posts

  • Create two global variables: g_score, g_hiscore.

    Add the Local Storage object to your project.

    Add this code to the start of your main event sheet:

    1. System|On start of layout: LocalStorage|Check item "savehiscore" exists

    2. LocalStorage|On item "savehiscore" exists: System|Set g_hiscore to LocalStorage.ItemValue

    3. LocalStorage|On item "savehiscore" missing: System|Set item "savehiscore" to 0

    This code checks whether you've already saved a hiscore to Local Storage - if you have it loads that value into your g_hiscore global variable, if you haven't it creates the item in Local Storage and then assigns it the value of 0.

    During your game session add whatever points you are scoring to g_score.

    At the end of the game session and before you start the next session add the following code into your event sheet:

    Edit: I forgot to include a trigger once:

    1Trigger Once:

    >>System| if g_score>g_hiscore: System|Set g_hiscore to g_score; LocalStorage| set item "savehiscore" to g_hiscore

    This code checks whether g_score is greater than g_hiscore and if so updates "savehiscore" in LocalStorage.

    If you've accessed other items in LocalStorage between retrieving "savehiscore" at the start and updating it at the end you may need to retrieve it again before updating (I think? Maybe someone can confirm)

    Hope that helps!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could check:

    if distance(player.X,player.Y,object.X,object.Y)<variable:

    set player position to (object.X,objectY)

    set movement to zero (i.e. stop inputs, bullet behaviour, whatever)

    variable would be whatever the maximum distance player can travel in 1 tick, to ensure you catch it (in fact I guess it could be half that distance - just have a play around with the figure).

    Distance returns the absolute value so it's direction independent.

  • RobertoFreemano

    Glad to be able to help

  • jhjconstruct

    You're welcome

    Sadly I'm uncertain how to go about exactly what you're after - it's something I really need to learn too (I've been spoiled by the convenience of bitballoon!) Hopefully somebody else on here will help us both out.

  • luckyrawatlucky

    Ah ok, my misunderstanding. If you want to keep the values as integers as you could push them to a 1D array, as oosyrag says.

  • Radulepy

    Just noticed that there is also a System event: General: Is number a NaN

  • This would work (I think) assuming that the surrounding objects are of the same type (object):

    Let's assume your objects are in a grid tile formation, with each object being the same dimensions as a tile.

    That means that any one object has neighbours in its 8 surrounding squares, including diagonals.

    We pick instance A, using whatever pick method you want (e.g. touch, a step function, etc)

    Set its x and y coordinates to a pair of local static variables, l_x and l_y,

    Set its width and height to a pair of local static variables, l_w and l_h

    We can now check each for each object in each direction around object A by using a pair of nested "for" loops.

    Add these conditions in the next event below the pick event (not as a sub event):

    System|For: "x" from -1 to 1
    System|For: "y" from -1 to 1
    System |Compare two values: If loopindex("x") does not equal 0
    System |Compare two values: If loopindex("y") does not equal 0
    System |Pick instance of objectX at (l_x+loopindex("x")*l_w,l_y+loopindex("y")*l_h) 
    [/code:2prskup1]
    
    Make sure they are all in the same event.
    The first condition is going to check the tiles to the left and right;
    The second condition is going to  check tiles above and below;
    The next two conditions exclude the tile you initially selected, where instance A is situated;
    The last condition picks the object instance that is a set coordinate distance from instance A by taking its current (x,y) position and either adding or subtracting its height or width .
    
    You can then grab whatever instance variable you want from the selected instance in the action e.g.:
    
    Set global variable checkThis to instance.myCheckThis.
    
    It gets trickier if you have different object types to check, but the same basic principle applies.
    
    Hope that makes sense!
  • Hi

    I am generating some objects randomly and its working good but if its getting delayed in starting the layout means from start screen if you delay in pressing "start" button all the object are getting loaded and all the objects coming at a time as a group.

    I have tried fixing this by grouping the events and deactivating this group on start of layout and activating on space bar is pressed but this didnt worked.How to fix this.Please help me.

    Thanks in advance

    I've a few questions for you that will help us get to the solution:

    1) Are you generating the same object type or different object types?

    2) How many objects are you trying to create?

    3) Do you want the objects to spawn at the same time or one at a time with a delay in between?

    4) Do you want to wait to spawn the objects until after the start button has been pressed?

  • Assuming that you will always start at 1, and going up to number X:

    Set text object text to "1"

    For "i" = 2 to X

    append text to text object ", "&loopindex("i")

    Make sure your text object is wide enough to see all the numbers (if you're feeling clever you could set the width of the text object based upon the value of X )

  • You could try using https://www.bitballoon.com/

    I'm not sure what their filesize limit is but you can drag your build folder directly into the box at the bottom of the home page to test. The service is free, you can rename the URLs and (I think) add a password. If you already have a Wordpress acct you could just add the link.

  • Ah, I've had something similar happen with local storage - you need to make sure the local storage variable is created and has a value before you can do anything with it, otherwise it will register as Nan.

    This is how I set it up, at the start of the main event sheet:

    System|On start of layout: Local Storage|check item "yourLSVariable" exists
    Local Storage|On item missing: Local Storage|set item "yourLSVariable" to (whatever value you want)[/code:3f4i0lfn]
    
    I also do the following check for if the item already exists and save it to a global variable:
    
    [code:3f4i0lfn]Local Storage|On item exists: set global variable "yourGlobalVariable" to LocalStorage.ItemValue[/code:3f4i0lfn]
    
    I can then work off the global variable instead of referring to the LocalStorage.  At the end of the session I can then save that global back our to local storage if needed.
    
    Another related tip - avoid putting any local storage events on a Loader layout, if you have one; I believe that once the game has downloaded once, the loader layout doesn't always play, in which case it would skip all those events.
  • orinab

    I am not a fan of wait actions. Because while you are waiting, you might need to change what should happen next.

    Heh, was just about to say the same thing, then noticed you'd posted: unless absolutely necessary I'd avoid waits, they have a habit of creating all sorts of problems unless used very carefully. If there's an alternative I'd use it - any of the other solutions mentioned here would be preferable.

  • Glad to have helped

  • You could get around it by creating a 2-D array and adding the names of the tags for a group of sounds to a column/row - this would allow you to place a sound in multiple groups.

    When you want to affect all sounds in a group you could then run a loop on that group, pointing the tag field in the relevant audio action.

    e.g.

    you have sounds tagged "sfx_A", "sfx_B", "sfx_C", "sfx_D"

    array_soundGroups has three groups of 3 sounds:

    0: ("A", "B", "C"),

    1: ("B", "C", "D"),

    2: ("D", "B", "A"),

    To turn off group 2:

    for "i"=0 to array_soundGroups.Height-1)

    stop sound tag "sfx_"&array_soundGroups@(2,loopindex("i"))

  • How about instead of creating a new thin red line object you:

    Add a new frame or animation to the platform object that includes the line graphic.

    Also add the fade out behaviour to the platform object.

    When the coin is collected switch the animation for all platforms.

    When the player collides with a platform you can then check if the new animation is playing. If so, start fade out behaviour for that platform. Make sure the "destroy on fade out" setting is set for the behaviour and the platform will automatically destroy once it's completely faded.