3 registered members (Ayumi, Akow, AndrewAMD),
1,505
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
OP
Senior Member
|
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.
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: Xarthor]
#241963
12/20/08 14:34
12/20/08 14:34
|
Joined: Jul 2002
Posts: 446 Switzerland
Mr Wurm
OP
Senior Member
|
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: Spirit]
#241977
12/20/08 16:16
12/20/08 16:16
|
Joined: Jul 2002
Posts: 446 Switzerland
Mr Wurm
OP
Senior Member
|
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. 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 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
User
|
User
Joined: Aug 2003
Posts: 902
Van Buren, Ar
|
Using your inkey function you could:
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.
|
|
|
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
OP
Senior Member
|
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
User
|
User
Joined: Aug 2003
Posts: 902
Van Buren, Ar
|
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.
|
|
|
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
OP
Senior Member
|
OP
Senior Member
Joined: Jul 2002
Posts: 446
Switzerland
|
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 . 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
OP
Senior Member
|
OP
Senior Member
Joined: Jul 2002
Posts: 446
Switzerland
|
Nvmind, I have discovered the meaning in your words, and the faults in my logic Now I know what it is, solving it is piece of cake.
- Mr Wurm
|
|
|
|