How am i able to let the User write a Text? (look last post )

Posted By: Espér

How am i able to let the User write a Text? (look last post ) - 10/30/08 16:58

Hi..

I´m a bit confues with that..

i tried

inkey(Karten_name)

Karten_name is a String that is shown in a visible Panel too ( to show the text the user is writing ).
But there´s no reaction.

How am i able to let the user write?
And how am i able to limit the input for each string ( karten_name shoudn´t be larger than 17 Signs )?
Posted By: Lukas

Re: How am i able to let the User write a Text? - 10/30/08 18:34

You have to show your string in a TEXT* instead of digits in a PANEL*.

How to limit the string length:
str_cpy(Karten_name,"#17"); // Karten_name consists of 17 spaces now.
inkey(Karten_name);

wink
Posted By: Espér

Re: How am i able to let the User write a Text? - 10/30/08 19:22

uhm.. i´m showing the name with that:

Code:
TEXT* namensfeld  =
{pos_x=21;pos_y=350;layer=20;font = goth;string(Karten_name);flags=VISIBLE;}


Looks like a Text.. not like a panel.. sry if i said wrong..

but, the String isn´t shown...
Posted By: falagar8

Re: How am i able to let the User write a Text? - 10/30/08 20:02


this may help you and others.
Or at least, start you off.....


//set up a TEXT object...
//with some text to input/display

#include<acknex.h>
#include<default.c>

STRING* temp1="#50";


//added another TEXT Object
//to ask for user for text input:
//TEXT object sg


TEXT* sg={ pos_x=50; pos_y=10; font="Arial#24"; alpha=90; string("Enter text: "); flags=TRANSLUCENT | VISIBLE; }

TEXT* sg1={ pos_x=100; pos_y=35; font="Arial#24"; alpha=90; string(temp1); flags=TRANSLUCENT | VISIBLE; }




function main()
{
video_mode=7;
screen_color.blue=255;


wait(2);



//place inputted text into string of temp1

inkey(temp1);




while(1)
{


if(key_c)
{
sg1.red=0;
sg1.green=0;
sg1.blue=0; }

if(key_d)
{
sg1.red=255;
sg1.green=255;
sg1.blue=255; }



wait(1);


}






}
Posted By: Uhrwerk

Re: How am i able to let the User write a Text? - 10/30/08 20:04

Please show us your complete code, i.e. String definition and the inkey use. Otherwise we can just do lucky guesses.
Posted By: falagar8

Re: How am i able to let the User write a Text? - 10/30/08 20:09

use the inkey(string*) to input,edit,backspace
your string that you are inputting. It is shown
on the screen while you are inputting or editing. But in this case only up to 50 chars or characters.
Since STRING* temp1; is a undefined string of up to 50 characters.

Good inputting wink

one more thing:

in the code that I posted...
the string(temp1) method attaches the STRING* temp1 to the Text object sg1.
this is solely diffrent if you omit this string() method.
and then use something like:

str_cpy(temp1, "STARGATE SG1");
str_cpy( (sg1.pstring)[0], temp1);

you are just copying the string contained in temp1 to the pstring
contents of the TEXT object sg1.
While if you attach temp1 thru the string(temp1) method
it will be attached to the TEXT object rather than the string being copied.
And in this case with temp1 being attached and inputted with inkey will show up and displayed on the screen while its being edited/inputted. Hence its attached to the Text object of sg1.

Get it? smile
Do you follow?

Posted By: Espér

Re: How am i able to let the User write a Text? - 10/31/08 11:09

Quote:
Get it? smile
Do you follow?

not really XD

but here are the code parts:

To define the String:
Code:
STRING* Karten_name = "#17";

To write a text into it:
Code:
function feldhandel()
{
	while(1)
	{
		if(textfeldnummer == 1)
		{
			inkey(Karten_name);
		}
		wait(1);
	}
}


textfeldnummer is a variable that is set to the number of the textfield you clicked on.

Here a Screen of the Editor:


The name field is declared with "Name der Karte". If i click with the mouse on it, textfeldnummer is set to 1.
Posted By: Anonymous

Re: How am i able to let the User write a Text? - 10/31/08 11:41

you have to display the String with a Text Object.
Posted By: Espér

Re: How am i able to let the User write a Text? - 10/31/08 11:45

i quote myself ( 5 post above ):
Quote:

uhm.. i´m showing the name with that:

Code:
TEXT* namensfeld =
{pos_x=21;pos_y=350;layer=20;font = goth;string(Karten_name);flags=VISIBLE;}



Looks like a Text.. not like a panel.. sry if i said wrong..

but, the String isn´t shown...


Like you see.. i show it with a text object..


EDIT:
Ok found out the problem.. the Message Boxes are white.. the text, too..
How am i able to change the text-color?
Posted By: Anonymous

Re: How am i able to let the User write a Text? - 10/31/08 11:53

Maybe you didn't called the function feldhandle.


test it:

www.extremegames-online.de/showimages/test.c

this is the code:
Code:

STRING* Karten_name = "#17";

var textfeldnummer = 1;

void feldhandle()
{
	while(1)
	{
		if(textfeldnummer == 1)
		{
			inkey(Karten_name);
			if(result == 13)   // pressing enter
			{ 
			textfeldnummer = 0;
			} 
		}
		wait(1);
	}
}

TEXT* namensfeld =
{
	pos_x=21;
	pos_y=350;
	layer=20;
	font = _a4font;
	string(Karten_name);
	flags=VISIBLE;
}


void main()
{
	level_load("");
	feldhandle();
}

Posted By: Xarthor

Re: How am i able to let the User write a Text? - 10/31/08 12:10

Color of the text:
add the red,green,blue parameters in the text object declaration:
Code:
TEXT* namensfeld =
{
  pos_x=21;
  pos_y=350;
  layer=20;
  font = goth;
  red = 1;
  green = 1;
  blue = 1;
  string(Karten_name);
  flags=VISIBLE;
}

By the way: your function for the input is ugly coded wink
If you really want to use a while loop then have a global variable which can be set to terminated that while loop.
Or (even better):
Use the button_number of the field (they would need to be buttons and sitting on one panel) to save the input in the right string.
Posted By: Anonymous

Re: How am i able to let the User write a Text? - 10/31/08 12:11

do you mean my code. Yeah i know its not good, but i adapted to the other code snippets here in this thread
Posted By: Espér

Re: How am i able to let the User write a Text? - 10/31/08 12:13

hey.. it´s my first input object i´m coding.. be gentle ^^

by the way: is there a code to stop stop the inkey without hitting Enter/Tab/PageDw/pageUp..etc?
And how to ask for the lengh of a string ( so if it reaches it´s maximal size, textfeldnummer is set += 1 ).
Posted By: Lukas

Re: How am i able to let the User write a Text? - 10/31/08 12:55

inkey_active = 0; // stop the inkey
string_length = str_len(Karten_name); // string_length is the length of Karten_name now.
Posted By: Xarthor

Re: How am i able to let the User write a Text? - 10/31/08 12:56

@Fear411: Nope I meant xXReapeRXx's code.

@xXReapeRXx:
[edit] see the post above
Posted By: Espér

Re: How am i able to let the User write a Text? - 10/31/08 17:51

thanks at all ^^

paste everyone of you to my info-window ^^
Posted By: falagar8

Re: How am i able to let the User write a Text? - 10/31/08 22:40


one thing that I will add is this:

there's a whole host or a a whole lotta of parameters,
attributes, and methods for each Object in 3D Game Studio.
Take the TEXT Object again.

The trick is to know what all or most of them are and do.
And have a passing reference for them.
Then learn what the basic or minimuns are to get something
up and running. As well as the defaults if they are included or
not included as you declare your TEXT Object in this case. For example in my simple code posted abouve I did not include the red,green,blue components. But by default they are 255 each for the whole total color to be white.
Then gradually and eventually pick and choose what attributes,paramaters,
and methods to use in your TEXT Object and also know their defaults if any too.
Those you use and include and those you don't use and neither include.

I hope this helps.
Posted By: Espér

Re: How am i able to let the User write a Text? - 10/31/08 23:53

not really XD
Posted By: EvilSOB

Re: How am i able to let the User write a Text? - 11/01/08 01:23

He means, when playing with new functions/objects, test how they work by
knowing how it behaves in its most simple fashion (ie defaults),
then make it more complex till you get what you need.

In your case create the TEXT object at its most simple, just displaying a static text
Code:
TEXT* namensfeld =
{
  string("testing text");
  flags=VISIBLE;
}
then update its complexity piece by piece till you get your desired result.
I would use the following steps, I know youve got the answer to them already,
but if you follow these sort of steps through anyway you can often catch faulty thinking
before it gets too buried in other stuff.

Starting from the somple code above, compile and test.
You see the text up the top left, and hopefully notice it is white.
Now only change its position, compile and test.
Cant see it anymore, now remember its color. Aha!
Now only change its color & position, compile and test.
Now you can see it, good. So add the goth font, compile and test.
Still looking good, OK so replace the fixed text with your Karten_name variable.
Compile and test.

Some of the more simple changes can be grouped together if you are certain of them all,
but the more complex each "step" is, the more places there are for logic faults to creep in.
End of tutorial....
Posted By: Espér

Re: How am i able to let the User write a Text? - 11/01/08 15:52

oh.. ok.. thanks ^^
Posted By: Espér

Re: How am i able to let the User write a Text? - 11/02/08 15:23

hmm.. got a new problem..

i will start a function via this:
Code:
if(textfeldnummer == 31){if(key_plus == 1){zahlenfeld_1_plus();wait(10);}}


The function has a beep(); at his beginning.. but that sound won´t appear..

This is the function:
Code:
function zahlenfeld_1_plus()
{
        beep();
	if(punktlimit >= 0)
	{
		lebenspunkte += speedcounter;
		punktlimit -= speedcounter;
	}
}


punktlimit is set to 10000 at startup...

Any idea why the function isn´t called? The Plus/Minus key should be the +/- from Numpad..
© 2024 lite-C Forums