Help with EditBox

This forum is currently in read-only mode.
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I'm making a simple money counting program. Something like..

    1c x 0

    5c x 0

    10c x 0

    .

    .

    100$ x 0

    sum = 0

    Where user would click on 0 and enter the number of coins or bills. I'm using EditBox with initial value 0, but I would need bigger font size. I can't find it in the EditBox only in the Text object.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I have been vexed by that as well. I don't think it can be changed. Because it's a windows API widget, it's not quite as integrated into Construct as most other objects. For instance, it can't be zoomed.

    Anyway, you might be able to make an acceptable alternative. linkman2004 made an example of a custom editbox a while back. It uses a hidden editbox to do the grunt work, while a Text and Box object make up the visible display. Something like that can be adapted to work with multiple fields.

    Check it out here:

    http://www.scirra.com/forum/viewtopic.php?f=16&t=5686&p=45360#p45360

    Another alternative that I just thought of, would be trying lucid's spritefont plugin. There is a recent tutorial that mentions using it as an editbox, here:

    http://www.scirra.com/forum/viewtopic.php?f=8&t=6867

    The plugin is linked to in that thread as well.

  • If you only need to input numbers you can accomplish it with just the Mouse&Keyboard and Text objects and two events:

    + System: For "" from 0 to 9
    + MouseKeyboard: On key LoopIndex + 25 pressed
    + System: Trigger once
    -> Text: Set text to int(.Text & LoopIndex)
    
    + MouseKeyboard: On key Backspace pressed
    -> Text: Set text to int(left(.Text, len(.Text)-1))
    [/code:1u3t3ixj]
    
    Here is a more advanced example that works with multiple instances of the text object and shows a blinking cursor on the selected instance:
    [url]http://dl.dropbox.com/u/5426011/examples/NumberInput.cap[/url]
  • Thank you Silent Cacophony and R0J0hound for your help. I've used bit of both. Here's what I've got so far

    http://dl.dropbox.com/u/10457408/Constr ... ncovka.cap

    http://dl.dropbox.com/u/10457408/Constr ... ncovka.exe

    It works but I still have some problems

    How can I make objects use variables, so I can make use of FOR

    object(x)

    object(x)

    .etc

    FOR "" 1 to 12

    object(LoopIndex)

    Look into the .cap, is there a way how to make it better optimized? I have On Click On Object for every 12 objects. Can I use just one event for all?

    When I input, say 25 into a box and than I click on that box again, the bleeping cursor in the EditBox stays at the beginning and adds numbers before 25 and not after.

    How can I add that bleeping cursor into a box so it will not look that empty

    Sorry for all those questions. I've wanted to use numbers for object names like 100 instead of onehundred but I got errors. And finally when I save the .cap on my home PC I can't open it on my work laptop even it's same version. I think, that I only have one plugin installed on home comp but it's not included in the .cap

    note - currency is in CZK

  • For the cursor moving to the front of the number it can be corrected with this sequence of actions:

    -> EditBox: Focus on

    -> EditBox: Select all

    -> EditBox: Cut

    -> EditBox: Paste

    It will put the cursor at the end, kind of hacky but it works.

  • There are a few ways to set the cursor to the end of the text in an EditBox. Here are two that I've used:

    EditBox.SelectAll()
    EditBox.ClearSelection()
    
    or:
    
    EditBox.SetSelection(len(EditBox.Text), len(EditBox.Text))[/code:1ck842a0]
    
    I greatly prefer the latter when the text is large, as it's faster, and prevents the selection flashing that the former causes. It just sets the start and end of the selection to the end of the text, which doesn't really select anything.
    
    As for making the .cap above with less events and separate objects, you can use a single Text object for all of those separate ones for the denominations, with private variables set differently for each instance to make them distinct. This can be done at runtime with a for loop that creates each instance at a different Y location, then sets an ID or Index private variable for each immediately after, using LoopIndex or something similar. Or, you can clone them in the layout editor, and set each manually there.
    
    I'd probably have a private variable for ID, Denomination, and Number. ID would be 1-12, Denomination could be set at runtime with [i]{1,2,5,10,20,50,100,200,500,1000,2000,5000}  LoopIndex[/i], and Number would store the number that has been input for that denomination.
    
    Also, this way you could do a for each to total the amount by adding Denomination * Number to another variable.
  • I was just thinking about this thing again, and wondered about how to do a cursor. I found that it is feasible, though it'd be a bit more complicated than I'd like to make for a multi-line editbox.

    It's pretty simple for a single-line box if you limit the text length so that you don't run out of the Text display area. Here's a quick example:

    http://dl.dropbox.com/u/5868916/EditBoxCursor.cap

    The cursor is just a sprite with the hotspot set to lower-left, and sine-opacity behavior.

    This doesn't handle shift-selecting very well, but hey... I'm sure that could be done, too.

  • Thanks again. I'm at work now, but I'll try it later. I've tried R0J0hound's cut/paste trick, but as you say I could see flashing (maybe I was doing it wrong), so I can't wait to try the other method

  • EditBox.SetSelection(len(EditBox.Text), len(EditBox.Text))[/code:1ktkrpco]
    This works perfectly and your EditBoxCursor too. I've had some problems with setting private variables and than calling them, but I think it's ok now.
    Now only what I have to do is put it all together. I'll try post final version next week
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)