Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,187 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Inkey in function entertains me with error messages [solved] #241949
12/20/08 13:46
12/20/08 13:46
Joined: Jul 2002
Posts: 446
Switzerland
Mr Wurm Offline OP
Senior Member
Mr Wurm  Offline OP
Senior Member

Joined: Jul 2002
Posts: 446
Switzerland
After spending near two days, trying all possible manipulations i could think off with this code, I would like to ask for help.

What I'm trying to do is get the player to enter a number thats passed back as the return of the function. Its a real simple piece of code, which is why I just for the world of me can't figure out where it goes wrong.
Quote:


STRING* s_t_input = "xx";
TEXT* t_input =
{
layer = 10;
pos_x = 0;
pos_y = 0;
string = s_t_input;
flags = VISIBLE;
}

int number_input(){
inkey((t_input.pstring)[0]);
str_to_int((t_input.pstring)[0]);
return(str_to_int((t_input.pstring)[0]));

}


I have tried using directly a string rather than a text element. Have tried waiting for inkey with wait_for(inkey(x));. Have tried waiting in while for inkey_active to turn to 0 again. Have also tried using inchar along the lines of the snippet in the manual.
Interestingly, when I move the code out of a dedicated function (unpractical but possible) it doesn't crash anymore, but instead of the code being executed multiple times, its executed one time, then never again. I'm baffled and sure its something completely obvious....but what?

Error I get is E1513. "Crash in number_input"

Thanks in advance for any suggestions.


- Mr Wurm

Re: Inkey in function entertains me with error messages [Re: Mr Wurm] #241960
12/20/08 14:23
12/20/08 14:23
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Why not just:
Code:
int number_input()
{
  result = inkey(s_t_input);
  if(result == 13)
  {
    return(str_to_int(s_t_input));
  }
}


Re: Inkey in function entertains me with error messages [Re: Xarthor] #241963
12/20/08 14:34
12/20/08 14:34
Joined: Jul 2002
Posts: 446
Switzerland
Mr Wurm Offline OP
Senior Member
Mr Wurm  Offline OP
Senior Member

Joined: Jul 2002
Posts: 446
Switzerland
I've replaced the funtion with your suggestion Xarthor, but it doesn't change anything. Still the same Error Message.

The behaviour I get is that the engine starts up, then shows the error message, after which the input function is called, so i can enter the number, but the value returned (observed through digit) doesen't match the input. Furthermore, the inkey is triggered only one time, when really it should be triggered twice.

Last edited by Mr Wurm; 12/20/08 14:34.

- Mr Wurm

Re: Inkey in function entertains me with error messages [Re: Mr Wurm] #241969
12/20/08 15:26
12/20/08 15:26
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
Your function has no crash bug, so something else is crashing in your script, but probably your calling the function in a wrong way. The "return" makes no sense.

When you want to do something with the entered string, you must wait until the user has pressed the enter key. But your function returns immediately before the user has entered anything. So you cant do anything with the return value.

Code:
int number_input()
{
   inkey((t_input.pstring)[0]);
   printf("%d",str_to_int((t_input.pstring)[0]));
}


function main()
{
   number_input();
   printf("Immediate return!");

}


Hope this helps.



Re: Inkey in function entertains me with error messages [Re: Spirit] #241977
12/20/08 16:16
12/20/08 16:16
Joined: Jul 2002
Posts: 446
Switzerland
Mr Wurm Offline OP
Senior Member
Mr Wurm  Offline OP
Senior Member

Joined: Jul 2002
Posts: 446
Switzerland
Thanks for your reply.

If I replace the inkey function with a dummy that just passes an ever increasing int every time it i called, I get no error.
Quote:

int number_input() //dummy
{
global_counter++;
return(global_counter-1);
}

//The way I call the function
int loc_i2 = number_input();


I see, so the problem lies in timing. Program skips ahead to what follows the function call with a value of 0, then after inkey is terminated the rest of the commands in the function are executed but its now too late to pass the int to the function which has already finished executing, wreaking havoc with the code.

At this point I am feeling like a total noob...So how can I make the function wait for the input? "while(number_input() == 0){wait(1);} doesn't seem to do the trick. Alternatively, just having

Quote:

int number_input(){
inkey((t_input.pstring)[0]);
result= str_to_int((t_input.pstring)[0]);
}

//and calling
number_input();
while(inkey_active != 0){ wait(1); }
wait(-1);
loc_i2 = result;

results in a similar overrun, because the function call is in a loop thats executed 3 times, I only get to enter the number once, after which the same number is feed back another 2 times.

I'm going bonkers over this...


- Mr Wurm

Re: Inkey in function entertains me with error messages [Re: Mr Wurm] #241982
12/20/08 16:36
12/20/08 16:36
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline
User
Gordon  Offline
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
Using your inkey function you could:

Code:
void number_input() {
   inkey((t_input.pstring)[0]);
   result= str_to_int((t_input.pstring)[0]);
}
 
//in your other function
for (i = 0; i < 3; i++) {
   number_input();
   while (proc_status(number_input)) {
      wait(1);
   }
   loc_i2 = result;
}


the reason for this is that inkey will internally exicute a wait and will cause your function to return to the caller.


Our new web site:Westmarch Studios
Re: Inkey in function entertains me with error messages [Re: Gordon] #241988
12/20/08 17:10
12/20/08 17:10
Joined: Jul 2002
Posts: 446
Switzerland
Mr Wurm Offline OP
Senior Member
Mr Wurm  Offline OP
Senior Member

Joined: Jul 2002
Posts: 446
Switzerland
Thanks Gordon. proc_status(x) finally did the trick. Since the function making the call was directly called 3 times in a list,
I needed an additional if(inkey_active !=){ wait(1); } to keep the three functions waiting for their turn. Now its _finally_ working....yesss! All that remains is to clean out all the clutter i added during trialanderroring

Thank you for your time everyone.



- Mr Wurm

Re: Inkey in function entertains me with error messages [Re: Mr Wurm] #241999
12/20/08 18:13
12/20/08 18:13
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline
User
Gordon  Offline
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
Quote:

Since the function making the call was directly called 3 times in a list,
I needed an additional if(inkey_active !=){ wait(1); }

you should also use the proc_status for the function that makes the calls in the list. This will give you freedom to change to any type of input you want later.


Our new web site:Westmarch Studios
Re: Inkey in function entertains me with error messages [Re: Gordon] #242045
12/21/08 00:18
12/21/08 00:18
Joined: Jul 2002
Posts: 446
Switzerland
Mr Wurm Offline OP
Senior Member
Mr Wurm  Offline OP
Senior Member

Joined: Jul 2002
Posts: 446
Switzerland
Code:
	
while(inkey_active != 0){	wait(1);	}
number_input();
while(proc_status(number_input)){wait(1);}
loc_i2 = result;


Thats the way it is now. And I guess I'll be writing the same thing whenever I'm calling the number_input(); function in my code. Not all that trim and pretty, but it works. Won't be requesting User input all that often anyways, luckily smile.

Not quite sure I understand what you are trying to say though Gordon. What do you mean with type of input? As I understand, the way the function is set up now, even if the mother function is called numerous times, the copies will queue for the bottleneck human, until one by one input has been given (hopefully in the order entered).

What do you mean with "freedom to change to any type of input"?

Last edited by Mr Wurm; 12/21/08 00:21.

- Mr Wurm

Re: Inkey in function entertains me with error messages [Re: Mr Wurm] #242124
12/21/08 14:29
12/21/08 14:29
Joined: Jul 2002
Posts: 446
Switzerland
Mr Wurm Offline OP
Senior Member
Mr Wurm  Offline OP
Senior Member

Joined: Jul 2002
Posts: 446
Switzerland
Nvmind, I have discovered the meaning in your words, and the faults in my logic blush
Now I know what it is, solving it is piece of cake.


- Mr Wurm


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