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
1 registered members (AndrewAMD), 599 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
What does inkey() return? #408849
10/08/12 15:10
10/08/12 15:10
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Hello JCL,

I'd like to know what inkey returns. The manual states it returns a number with the ascii code that caused inkey to return, so my first guess was it returned a char, int or fixed. Given that I couldn't explain to myself why
Code:
while (27 != inkey(console_in_buf));

kept failing.
A closer look at acknex.h showed me that inkey returns a STRING*? Could you give me some insights? I don't get it ...


Always learn from history, to be sure you make the same mistakes again...
Re: What does inkey() return? [Re: Uhrwerk] #408851
10/08/12 15:38
10/08/12 15:38
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
inkey some kind of strange, yes...
just try this:
Code:
var ikr;
do
{
ikr = inkey(console_in_buf);
} while(ikr != 27);


This is because of the scheduler. The line gets executed before the inkey starts working...
so your while loop never gets executed correctly
but if you unpack the single line into multiple lines inkey works correctly


Visit my site: www.masterq32.de
Re: What does inkey() return? [Re: MasterQ32] #408852
10/08/12 15:52
10/08/12 15:52
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
If that is the case it's a bug from my point of view. inkey should either always block until a return value is available or never. Btw. this works as well:
Code:
fixed x;
while (27 != (x = inkey(console_in_buf)));


Basically you have the same situation here, inkey embedded in an expression inside the condition of a while loop. So your theory could explain why my code does not work. I'm still confused by the STRING* return type of inkey though.


Always learn from history, to be sure you make the same mistakes again...
Re: What does inkey() return? [Re: Uhrwerk] #408919
10/09/12 12:09
10/09/12 12:09
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
It returns a var, and MasterQ32 is correct: it's a scheduler function just as wait(). The STRING* return definition in acknex.h is indeed strange and apparently had a reason in a compatibility issue with CScript. It's also obviously the reason why the other code examples worked, but not the first one. We'll change this in the next update so that you don't need to assign the return value to a var.

If you edit acknex.h yourself and change STRING* to var, your first example should also work.

Re: What does inkey() return? [Re: jcl] #409018
10/10/12 13:13
10/10/12 13:13
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Thank you for your help!


Always learn from history, to be sure you make the same mistakes again...
Re: What does inkey() return? [Re: Uhrwerk] #409068
10/11/12 01:45
10/11/12 01:45
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I have to add two things:

key_pressed does not work in the frame inkey ends in. If you e.g. have the following code:
Code:
STRING* s = str_create("#32");
fixed c = inkey(s);
if (key_pressed(42))
    beep();


the beep will never be executed, regardless of the shift key. The same is true for the control key and the variables key_shift etc. That's a bit annoying because you cannot detect if the input was ended with ctrl+enter or shift+enter. It works one frame later though.

Could you please also have a look at http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=408805#Post408805, because nobody seems to be able to answer it. Did my mind play a trick on me or did such a function exist?


Always learn from history, to be sure you make the same mistakes again...
Re: What does inkey() return? [Re: Uhrwerk] #409073
10/11/12 09:41
10/11/12 09:41
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
Yes, inkey and inchar switches off all other key functions - that is mentioned in the manual. Only after inkey/inchar ended you can again use the normal key events and variables.

There is no function to set the cursor position, but you can set it in the STRING struct. You must redefine the STRING struct in atypes.h for this:

Code:
typedef struct STRING {
	C_LINK	link;
	char	*chars;		// pointer to null terminated string
	long	length;		// allocated length of string
	long	flags;		// see STRF_... above
	long	CRLFcnt;
	long	cursor;     //0 kein Cursor !=0 Cursor position 
} STRING;


Re: What does inkey() return? [Re: jcl] #409077
10/11/12 10:17
10/11/12 10:17
Joined: Dec 2008
Posts: 1,218
Germany
Rackscha Offline
Serious User
Rackscha  Offline
Serious User

Joined: Dec 2008
Posts: 1,218
Germany
@JCL Why is a redefinition possible here? If this is already part of the internal string struct, how about adding it to the official atypes.h?(and adding all available filed of all internal structs too, if there is more hiding in the drak tongue )


MY Website with news of my projects:
(for example my current
Muliplayer Bomberman,
GenesisPrecompiler for LiteC
and TileMaster, an easy to use Tile editor)
Sparetime-Development

Re: What does inkey() return? [Re: Rackscha] #409083
10/11/12 11:00
10/11/12 11:00
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
there is more hiding in the dark, just look at all those padding variables ^^


Visit my site: www.masterq32.de
Re: What does inkey() return? [Re: MasterQ32] #409116
10/11/12 20:07
10/11/12 20:07
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Probably used to hold nasty messages about our mothers...

@Rackscha: The field is already there, like masterQ32 pointed out. The reason why they aren't public is most likely that they are subject to change. They aren't meant to tinker with and might break in the next engine revision. So just like every un-exposed and private API.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Page 1 of 2 1 2

Moderated by  old_bill, Tobias 

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