How do I use text input to identify a target point?

  • I’m creating an educational game that allows the user to identify a Grid location using text then ordering a strike onto that position. A bit like battleships. I’ve created a layer for my grid in which I have placed sprites to represent each of the grid squares and these of course are invisible to the user. So what I can’t seem to figure out is how I can... allow the user to input the relevant grid(sprite) name into the text box. To link a button that “executes” the order and would generate a plane sprite to fly over and bomb the location. Any thoughts?? Lol hope you guys can help.

  • I'm not exactly sure how you have things set up, but I'll assume you have 2 text boxes, one for the X coordinate and one for the Y coordinate. If it's just a single text box you can parse out the individual X and Y by using the system expressions tokenat(src, index, separator) & tokencount(src, separator) system expressions.

    Since you have sprites to represent each grid space you could give those sprites 2 instance variables to represent their X and Y grid positions.

    Now you can just pick the sprite where the coordinates from the text box match the coordinates of the sprite. Then you can use the X, Y layout coordinates of the sprite so you know where to perform the strike.

    There's other more mathematical ways you could accomplish the same thing, but since you already stated you have individual sprites to represent the grid spaces, this should work.

    I hope that helps.

  • So, I have a single text box. and a single button next to it. I have several "Grid" sprites on a layer underneath the main Layer. Each of the Sprites is 'named' the Grid square that it represents, (st2345, st2346, st2347, Etc.) So my conundrum is...

    How do I get the Player to input the 'grid' into the text box, and then when they press the button next to the grid square, it will start an event which [would include creating a Sprite, which is remarkably shaped like a Bomber, fly in from off screen towards the 'grid sprite' identified and carpet bomb the 'grid sprite' in question? I have all the relevant sprites animated, the bomber the carpet bombing animations, i just need help with linking the action of writing in the text box, and 'launching' the attack. Hope this clarifies it a little more. In my amature amatureish understanding of the coding and event process, I reckon it would be easier to target a sprite with the grid name rather than creating an algorithym that identifies coordinates into grid spaces. This game and process will hopefully be used to help learn and practice four figure and six figure grid reading.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Add an instance variable "squareCode" to the Grid sprite, set correct value in it for each Grid instance.

    When user enters square code into the InputBox and presses the button, pick Grid sprite:

    Grid Compare instance variable squareCode=InputBox.text
    	// you can fly your Bomber to Grid location using Bullet, MoveTo or some other behavior
    Else 
    	// Display a message to user saying that the code is wrong
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)