|
1 registered members (AndrewAMD),
599
guests, and 3
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
What does inkey() return?
#408849
10/08/12 15:10
10/08/12 15:10
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
OP
Expert
|
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
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
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
inkey some kind of strange, yes... just try this:
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
|
|
|
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
OP
Expert
|
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:
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]
#409068
10/11/12 01:45
10/11/12 01:45
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
OP
Expert
|
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:
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: jcl]
#409077
10/11/12 10:17
10/11/12 10:17
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
Serious User
|
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  )
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: MasterQ32]
#409116
10/11/12 20:07
10/11/12 20:07
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
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
|
|
|
|