Help with user-defined tilt angle.

Posted By: MattyTheG

Help with user-defined tilt angle. - 11/25/08 14:56

Last coding question for a while, I promise :P
Anyway I am working on this game where I want the user to be able to enter a number and have that number be set to the launch angle/ tilt of the gun. I have a global variable and a string, I use inkey to get the string and then str_to_num to convert it to a number, but then I used my.tilt = number, and it doesn't affect it. Perhaps seeing the code is better.

Code:
STRING* test = "    ";
var user_num = 0.00;

action gun_shoot()
{
	result = inkey(test);
	if (result == 13)
	{
		user_num = str_to_num(test);
		my.tilt = user_num;
	}
}


I don't understand why this wouldn't set my.tilt to the user_num.

I have a panel with the code "digits(300,40,"Launch angle: %f", *, 1, user_num);" and even after I enter the number I want, it still says 0.0000, so perhaps there is a problem with the string_to_num()?
Posted By: delinkx

Re: Help with user-defined tilt angle. - 11/25/08 16:01

put a breakpoint inside the

if(result == 13)
{
....
...
}

and check if control is going there. I don't think its accepting keyboard entry like this.
Posted By: MattyTheG

Re: Help with user-defined tilt angle. - 11/26/08 00:48

I think you're right. The manual shows it as calling a process_entry() function later but does not go into details as to what that function contains.
Would a code more like this work?
Code:
function process_entry(test)
{
   user_num = str_to_num(test);
}

action gun_shoot()
{
   result = inkey(test);
   if (result == 13)
   {
      process_entry(test);
   }
}


Something like that? I'm not sure what you mean by a breakpoint, I know how to use the break command in C++ but not sure what to do here.

Posted By: heinekenbottle

Re: Help with user-defined tilt angle. - 11/26/08 00:53

a breakpoint is a //! at the end of a line that will, if you run with -debug, single step through a program if that instruction was reached.

Alternatively, you could use beep() in the if branch to see if the code is going that far.
Posted By: MattyTheG

Re: Help with user-defined tilt angle. - 11/26/08 01:18

Alright, thanks for clarifying that. Yea I used the beep() and there was no beep, so apparently the key command is not processing. Does anyone know why it wouldn't? I terminated the text with enter which is supposed to return 13 according to the manual.
Posted By: Widi

Re: Help with user-defined tilt angle. - 11/26/08 22:00

There is a Bug in version 7.07, the inkey dont return the number of the key. I have the same problem. Use:

inkey(test);
if (result == 13)

and not:

result = inkey(test);
if (result == 13)
Posted By: MattyTheG

Re: Help with user-defined tilt angle. - 11/26/08 23:04

That fixed the problem, thank you very much.
© 2024 lite-C Forums