Keypad Entry Problem

Next
 From:  bemfarmer
7012.1 
Hi Michael

November 3, 2014

I am having trouble with keypad entry, on a home-made script.

Recently, Max Smirnov posted the Gear script, which works very well.
It uses a 30 ms timing loop, with most of the code in the .htm file.
All of the keypad numeric entry is with POSITIVE integers.
There is no minus key, nor decimal key.
Every time a number key is pressed, the gear is recreated.

I redid the elastica script, using the Gear type of code.
(The script uses numbers less than positive 1.0)
The slider works very well, and the OnClick works well also.
There is a problem with the numeric keypad entry, when using negative numbers. There is a minus key, and a decimal key, which cause problems.

The first time the keypad is used, it works well. The minus key works properly.

The second time the keypad is used, positive numbers enter properly, but
minus entry or decimal entry caused the keypad to freeze up.
Second time entry examples:
0 works
0.5 works
.5 fails
0.5- works
0.65223 works
0.65223- works
.65223 Fails
- anynumber Fails
1.2- works
Miss keys like 0.5. Fail
Alternating between 1 keypad entry, and slider or onclick, works.

So the script is grabbing each key from the keypad, as it is pressed.
For example . or - which are not numbers.

Is there some way to let the keypad finish up, before the keys are grabbed?
Or is this scripting method not appropriate?

I'll likely redo the script with earlier .htm scripting methods.
Using mirror and rotate, the script creates the entire curve (or two), not a 1/4 or 1/2

Thank you
- Brian

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
7012.2 In reply to 7012.1 
Hi Brian, yeah that's set up fairly differently than how regular MoI command scripts run. The usual method is to read values out of the input controls only once a UI event has been triggered, that's in the .js file where you have an event loop that does:

code:
	while ( 1 )
	{
		if ( !dialog.waitForEvent() )
                ....




You asked:

> Is there some way to let the keypad finish up, before the keys are grabbed?

Yeah it should be possible by waiting for the UI event for the input control to be triggered, and when that is received set a flag for the continuously updating loop to recalculate.

That would look something like this:

code:
		if ( dialog.event == 'done' ) break; // "Done" pushed.

		if ( dialog.event == 'U' )
		{
			// The input with id="U" has finished receiving input, characters have been typed and Enter
			// pushed or OK on the popup keypad has been pushed, now let an update happen.
                
			moi.ui.commandUI.SomeFlagForDoUpdate = true;
		}


Then on the .htm side make it look for the "SomeFlagForUpdate" variable and only let it go forward with processing things if that is set to true.


This kind of a thing with a constantly going script on a timer can be problematic with it trying to access the UI (with getting sort of "in between" values like this), if it's triggered more in response to UI events then that should probably help.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
7012.3 In reply to 7012.1 
Hi Brian, also probably what is messing up your actual script is if you have characters like just a plain - or . as the text content in a NumericInput field, when you try to retrieve the .value property of that control you'll get the JavaScript 'undefined' value as the result rather than an actual number.

So another way to guard against this problem is to look if any of those fields have an 'undefined' value and bail out from further processing if that's the case.

That would be something like this:

code:
			function UpdateElastica()
			{
				if ( P.value === undefined || U.value === undefined || WD.value === undefined )
					return;


I think with this added in as the first line of the update function it should avoid your problem.

Before maybe your script is getting stuck in an infinite loop or something because it's expecting those values to be numbers but they're actually 'undefined'.

Please let me know if you still see any problems after adding this in.

- Michael

EDITED: 4 Nov 2014 by MICHAEL GIBSON

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
7012.4 In reply to 7012.3 
Thank you very much Michael.

Will try your answers.

I had tried NAN, which is incorrect :-)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
7012.5 In reply to 7012.4 
Hi Brian, NaN was a good guess, but yeah 'undefined' is maybe a bit more universal which would maybe work with any kind of control even non-numeric stuff.

The other possibility was to throw an exception if you try to get the .value and there is no numeric representation of it... But that can be somewhat annoying to deal with as well.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  bemfarmer
7012.6 In reply to 7012.5 
Undefined works very well!

I have not observed any problems, so I will post _elastica2 under its topic.

- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All