Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
2 registered members (3run, AndrewAMD), 667 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
keyboard input as string #401530
05/21/12 12:10
05/21/12 12:10
Joined: Jul 2011
Posts: 10
S
stuted Offline OP
Newbie
stuted  Offline OP
Newbie
S

Joined: Jul 2011
Posts: 10
Hey

i am mainly a c++ programmer, i need to get used to this language. What i want to ask, what can i use to get input from the user, like i could with std::cin?
I want to put the info into a string.

Code:
typedef struct
{
	int health;
	int armor;
	int attack;
	
	STRING* name;
} CREATURE;



here is my struct. I would like to put the input into the instance of CREATURE called plr. so plr.name.

Re: keyboard input as string [Re: stuted] #401532
05/21/12 12:15
05/21/12 12:15
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline
Serious User
PadMalcom  Offline
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Look at the function inkey().

Re: keyboard input as string [Re: PadMalcom] #401534
05/21/12 12:26
05/21/12 12:26
Joined: Jul 2011
Posts: 10
S
stuted Offline OP
Newbie
stuted  Offline OP
Newbie
S

Joined: Jul 2011
Posts: 10
Okey, i am using it, but how come now, if i use TEXT*

Code:
inkey(plr.name);
	
	TEXT* out_test =
	{
		pos_x = 300;
		pos_y = 250;
		layer = 1;
		font = "Arial#14b";
		string = (plr.name);
		flags = SHOW;		
	}



I get an error that says: plr.name invalid charater?

Last edited by stuted; 05/21/12 12:27.
Re: keyboard input as string [Re: stuted] #401560
05/21/12 16:55
05/21/12 16:55
Joined: Sep 2009
Posts: 987
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 987
Budapest
Maybe better if you use inchar instead of inkey.
Read the manual and you will be enlightened.

Re: keyboard input as string [Re: Aku_Aku] #401580
05/21/12 21:01
05/21/12 21:01
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline
Serious User
PadMalcom  Offline
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Can you post your entire code?

Re: keyboard input as string [Re: PadMalcom] #401582
05/21/12 21:16
05/21/12 21:16
Joined: Jul 2011
Posts: 10
S
stuted Offline OP
Newbie
stuted  Offline OP
Newbie
S

Joined: Jul 2011
Posts: 10
Here comes the full code:
Code:
//#include <acknex.h>
#include <litec.h>
#include <default.c>

void initalize(void);

typedef struct
{
	int health;
	int armor;
	int attack;
	
	STRING* name;
} CREATURE;

void main()
{
	initalize();
	
}

void initalize(void)
{
	screen_size.x = 800;
	screen_size.y = 600;
	
	CREATURE plr;
	plr.health = 100;
	plr.armor = 10;
	plr.attack = 5;
	
	//FONT* arial_font = "Arial#14b";
	
	TEXT* greetings =
	{
		pos_x = 200;
		pos_y = 150;
		layer = 1;
		font = "Arial#14b";
		string("Welcome to this adventure game! Please enter a name for your new character: ");
		flags = SHOW;		
	}
	
	inkey(plr.name);
	
	TEXT* out_test =
	{
		pos_x = 300;
		pos_y = 250;
		layer = 1;
		font = "Arial#14b";
		string = (plr.name);
		flags = SHOW;		
	}
}



Thank you for your time.

Re: keyboard input as string [Re: stuted] #401589
05/22/12 06:13
05/22/12 06:13
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
Hi,

I made some changes to your code :

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

// Text used to show input
TEXT* input_test =
{
	pos_x = 300;
	pos_y = 250;
	layer = 1;
	font = "Arial#14b";
	strings = 1;
	flags = SHOW;		
}

// Show player name
TEXT *out_test = 
{
	pos_x = 300;
	pos_y = 300;
	font = "Arial#32b";
	strings = 1;
	//flags = SHOW;
}

// Greetings text
TEXT* greetings =
{
	pos_x = 200;
	pos_y = 150;
	layer = 1;
	font = "Arial#14b";
	string("Welcome to this adventure game! Please enter a name for your new character: ");
	flags = SHOW;		
}

void initalize(void);

typedef struct
{
	int health;
	int armor;
	int attack;
	
	STRING* name;
} CREATURE;

void main()
{
	initalize();	
}

void initalize(void)
{
	screen_size.x = 800;
	screen_size.y = 600;
	
	CREATURE plr;
	plr.health = 100;
	plr.armor = 10;
	plr.attack = 5;
	
	// Init string with length
	plr.name = str_create("#255");
	
	// Attach the string to the text
	(input_test->pstring)[0] = plr.name;
	
	// Get player Name
	inkey((plr.name));
	
	/// Print player name into the second panel
	// Hide input panel
	input_test->flags &= ~SHOW;
	
	// Show out panel, and set text color
	out_test->flags |= (SHOW | FILTER | LIGHT);
	out_test->blue = 150;
	out_test->red = 20;
	out_test->green = 160;
	// Copy player name into out_test string
	str_printf((out_test->pstring)[0], "Chracter name : \"%s\"", _chr(plr.name));
}



Best regards.

Re: keyboard input as string [Re: 3dgs_snake] #401596
05/22/12 09:05
05/22/12 09:05
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline
Serious User
PadMalcom  Offline
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
To explain it:

TEXT* definitions may only occure outside of functions. If you want to create TEXTs inside a function use the function txt_create.

As you might know as c++ programmer you have to initialize everything that is defined as pointer. So you have to create the plr.name using str_create as 3dgs_snake did.

Re: keyboard input as string [Re: PadMalcom] #401598
05/22/12 11:32
05/22/12 11:32
Joined: Jul 2011
Posts: 10
S
stuted Offline OP
Newbie
stuted  Offline OP
Newbie
S

Joined: Jul 2011
Posts: 10
Oh thanks for the code and the explain. It takes time to get used to lite-c.

Re: keyboard input as string [Re: stuted] #401599
05/22/12 11:47
05/22/12 11:47
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline
Serious User
PadMalcom  Offline
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Yepp, but when you've got it is easy to work with it!


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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