mekonbekon's Recent Forum Activity

  • You can store array items in a json file (just rename with *.json instead of *.txt) in the following format:

    {

    "c2array":true,

    "size":[5,6,1],

    "data":

    [ [

    [0],[1],[0],[-1],[-1], [0.5]], [

    [1],[0],[1],[0],[-1], [0.5]], [

    [0],[3],[1],[3],[-1], [0.5]], [

    [1],[3],[0],[3],[-1], [0.5]], [

    [2],[3],[2],[3],[-1], [0.5]],

    ]

    }

    You can make the data items what ever you want, of course.

    You can make the array as big as you like and even turn it into a 3D array by adding extra items within the inner square brackets, just make sure to adjust the size values at the top.

    Import the file into the files folder for your project on the "Project" tab.

    Add an array object to your game (e.g. yourArrayObject)

    Add the AJAX object.

    System|On start of layout: AJAX| Request (your json).json (tag "your tag")

    AJAX | On "your tag" completed: yourArrayObject|Load from JSON string AJAX.LastData

    This will grab your json array and add it to the array object - I don't think you have to stipulate the size of your array object - it should automatically fill up from the json - but it probably doesn't hurt to set the dimensions the same.

    Hope that makes sense!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've updated the code above as I'd missed out a "trigger once" in the second section.

    This should work for saving your highest score, not your most recent - it's what I'm currently using in my projects without any problems.

    Do you have a capx you can share?

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

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

mekonbekon's avatar

mekonbekon

Early Adopter

Member since 9 May, 2014

Twitter
mekonbekon has 13 followers

Trophy Case

  • 10-Year Club
  • Forum Contributor Made 100 posts in the forums
  • Forum Patron Made 500 posts in the forums
  • x2
    Popular Game One of your games has over 1,000 players
  • Famous Game One of your games has over 10,000 players
  • Coach One of your tutorials has over 1,000 readers
  • RTFM Read the fabulous manual
  • Great Comment One of your comments gets 3 upvotes
  • Email Verified

Progress

18/44
How to earn trophies