Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Imhotep, opm), 785 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Is Text Box data check possible? #479083
02/13/20 14:49
02/13/20 14:49
Joined: Jan 2012
Posts: 108
G
gamers Offline OP
Member
gamers  Offline OP
Member
G

Joined: Jan 2012
Posts: 108
Hello there,
How can I check if any data is entered into the textbox by users?
Also, how can I ensure that only numbers are entered in the text box?
Is it possible?

Re: Is Text Box data check possible? [Re: gamers] #479084
02/13/20 15:25
02/13/20 15:25
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Hey!

If you store text into the string, you can check it's length (str_len). As for 'numbers only' maybe str_stri can help, just a quick thought.

Greets!

Edit: I think str_stri was a bad idea, not going to work...probably str_cmpi is a better for this case.

Edit2: I've spent a little time and came up with this (since I don't know how to handle regex with lite-c and it might not even support it):
Code
#include <acknex.h>
#include <default.c>

#define PRAGMA_POINTER

STRING *non_numeric_str = "0123456789a";
STRING *numeric_str = "5325";
STRING *empty_str = "";

// receives a STRING and position (num) of a character in that STRING
// returns a single character as a STRING
STRING *get_next_char(STRING *src_str, int num)
{
	if(!src_str)
	{
		return NULL;
	}
	
	if(num > str_len(src_str))
	{
		return NULL;
	}
	
	STRING *temp_str = "";
	str_cpy(temp_str, src_str);
	str_trunc(temp_str, str_len(src_str) - num);
	str_clip(temp_str, num - 1);
	
	return temp_str;
}

// returns TRUE (1) if string is numeric
// otherwise returs FALSE (0)
var is_numeric_str(STRING *src_str)
{
	if(!src_str)
	{
		return false;
	}
	
	int i = 0, j = 0, res = true;
	
	for (i = 0; i < str_len(src_str); i++)
	{
		STRING *temp_str = get_next_char(src_str, i + 1);
		
		for (j = 0; j < 10; j++)
		{
			if (!str_cmpi(temp_str, str_for_num(NULL, j)))
			{
				res = false;
				continue;
			}
			
			res = true;
			break;
		}
		
		if(res == false)
		{
			break;
		}
	}
	
	return res;
}

// returns TRUE (1) is string's length is zero
// otherwise returns FALSE (0)
var is_empty_str(STRING *str)
{
	if(!str)
	{
		return false;
	}
	
	if(str_len(str) > 0)
	{
		return false;
	}
	else
	{
		return true;
	}
}

// main game function
void main()
{
	var numeric1 = is_numeric_str(non_numeric_str);
	var numeric2 = is_numeric_str(numeric_str);
	var empty = is_empty_str(empty_str);
	
	while(!key_esc)
	{
		DEBUG_VAR(numeric1, 0);
		DEBUG_VAR(numeric2, 20);
		DEBUG_VAR(empty, 40);
		
		wait(1);
	}
}


Edit3: my code above probably is not the best and easiest ways... I just wanted to give it a try. hopefully some other users may point out a better solution.

Last edited by 3run; 02/13/20 21:33.

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Is Text Box data check possible? [Re: 3run] #479087
02/14/20 12:50
02/14/20 12:50
Joined: Jan 2012
Posts: 108
G
gamers Offline OP
Member
gamers  Offline OP
Member
G

Joined: Jan 2012
Posts: 108
Originally Posted by 3run
Hey!

If you store text into the string, you can check it's length (str_len). As for 'numbers only' maybe str_stri can help, just a quick thought.

Greets!

Edit: I think str_stri was a bad idea, not going to work...probably str_cmpi is a better for this case.

Edit2: I've spent a little time and came up with this (since I don't know how to handle regex with lite-c and it might not even support it):
Code
#include <acknex.h>
#include <default.c>

#define PRAGMA_POINTER

STRING *non_numeric_str = "0123456789a";
STRING *numeric_str = "5325";
STRING *empty_str = "";

// receives a STRING and position (num) of a character in that STRING
// returns a single character as a STRING
STRING *get_next_char(STRING *src_str, int num)
{
	if(!src_str)
	{
		return NULL;
	}
	
	if(num > str_len(src_str))
	{
		return NULL;
	}
	
	STRING *temp_str = "";
	str_cpy(temp_str, src_str);
	str_trunc(temp_str, str_len(src_str) - num);
	str_clip(temp_str, num - 1);
	
	return temp_str;
}

// returns TRUE (1) if string is numeric
// otherwise returs FALSE (0)
var is_numeric_str(STRING *src_str)
{
	if(!src_str)
	{
		return false;
	}
	
	int i = 0, j = 0, res = true;
	
	for (i = 0; i < str_len(src_str); i++)
	{
		STRING *temp_str = get_next_char(src_str, i + 1);
		
		for (j = 0; j < 10; j++)
		{
			if (!str_cmpi(temp_str, str_for_num(NULL, j)))
			{
				res = false;
				continue;
			}
			
			res = true;
			break;
		}
		
		if(res == false)
		{
			break;
		}
	}
	
	return res;
}

// returns TRUE (1) is string's length is zero
// otherwise returns FALSE (0)
var is_empty_str(STRING *str)
{
	if(!str)
	{
		return false;
	}
	
	if(str_len(str) > 0)
	{
		return false;
	}
	else
	{
		return true;
	}
}

// main game function
void main()
{
	var numeric1 = is_numeric_str(non_numeric_str);
	var numeric2 = is_numeric_str(numeric_str);
	var empty = is_empty_str(empty_str);
	
	while(!key_esc)
	{
		DEBUG_VAR(numeric1, 0);
		DEBUG_VAR(numeric2, 20);
		DEBUG_VAR(empty, 40);
		
		wait(1);
	}
}


Edit3: my code above probably is not the best and easiest ways... I just wanted to give it a try. hopefully some other users may point out a better solution.


Thanks for your contribution. I will try this as soon as possible.

Re: Is Text Box data check possible? [Re: 3run] #479094
02/17/20 11:09
02/17/20 11:09
Joined: Jan 2012
Posts: 108
G
gamers Offline OP
Member
gamers  Offline OP
Member
G

Joined: Jan 2012
Posts: 108
Is there any way to limit the value to be written in the text box between 0 and 100?

Re: Is Text Box data check possible? [Re: gamers] #479095
02/17/20 14:05
02/17/20 14:05
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
I think it depends on how you created your text box. As far as I know, there is no default text box in acknex... if you use (f.e.) imgui there is already implemented text box with limitation etc.. You can check it out here.

Best regards!

Edit: maybe I misunderstood your question.. to input only 0...99 numbers, I would check for the length on the string (make sure it's numeric), if the length >= 3, then value is 100 and higher.

Last edited by 3run; 02/17/20 14:07.

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Is Text Box data check possible? [Re: 3run] #479098
02/18/20 05:29
02/18/20 05:29
Joined: Jan 2012
Posts: 108
G
gamers Offline OP
Member
gamers  Offline OP
Member
G

Joined: Jan 2012
Posts: 108
Thank you for your answer 3run. Actually, I want to use only the textbox part of IMGUI. How can I do that? In other words, I want to create a text box that I want, to ensure that the data entered is only between 0 and 100, and to check whether the data is entered or not, and to warn the user if any data has not been entered into textbox.

Re: Is Text Box data check possible? [Re: gamers] #479100
02/18/20 07:20
02/18/20 07:20
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
So, you want to input box for only numbers, between 0&100. Here is another way. Not the good one but at least it can give some idea;

Code
#include <acknex.h>


STRING* defstr="#100";
STRING* test_str="";


//is input box open
int is_input_box_on=0;

//test variable
int test_num;

//debug
function textx_startup()
{
	while(1)
	{
		if(is_input_box_on==1)
		{
			draw_text("Enter any number",1,1,COLOR_GREEN);
			draw_text(test_str,1,200,COLOR_GREEN);

			
		}
		DEBUG_VAR(test_num,20);
		wait(1);
	}
}

function on_f1_event() 
{
	beep();
	
	//clear all strings

	str_cpy(test_str,"");
	test_num=0;
	

	

	char this_char = 0;
	is_input_box_on=1;
	
	while(this_char!=13)//wait until press enter
	{
		

		this_char = inchar(defstr);
		if(this_char!=1)  
		{
			//if is numeric
			if(str_stri(this_char,"0")||
			str_stri(this_char,"1")||
			str_stri(this_char,"2")||
			str_stri(this_char,"3")||
			str_stri(this_char,"4")||
			str_stri(this_char,"5")||
			str_stri(this_char,"6")||
			str_stri(this_char,"7")||
			str_stri(this_char,"8")||
			str_stri(this_char,"9"))
			{
				str_cat(test_str,defstr);
				
			}
			else
			{
				//if isn't numeric don't do anything
			}
			
		}
		wait(1);
	}

	//convert string to number
	test_num=str_to_int(test_str);
	
	//turn of the box
	is_input_box_on=0;

	
	//if bigger than 100
	if(test_num>100)
	{
		printf("Error: Value is bigger than 100!");
		
		//try again
		on_f1_event(); 
	}

}




function main()
{

	on_f1_event();
}
void on_esc_event()
{
	sys_exit("");
}


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1