Page 1 of 1

[NXC] Improve Help File

Posted: 05 Feb 2011, 01:14
by muntoo
Here you can post examples, fixes, etc for the NXC Help File. Hopefully, John Hansen will update the help file to accommodate your improvements.

For example, ex_SetVMRunState.nxc, contains the following at the moment this post was written:

Code: Select all

SetVMRunState(0); // stopped
Not too helpful, eh? Try your hand at improving it. This is a little better:

Code: Select all

SetVMRunState(UI_VM_IDLE); // stopped
*Disclaimer: I don't really understand what this code does. :)

There's many of these types of "examples" ** out there:

Code: Select all

y = ceil(x);
Could be improved to:

Code: Select all

float a = ceil(3.01);
// a == 4.0
float b = ceil(3.14);
// b == 4.0
float c = ceil(3.99);
// c == 4.0
float d = ceil(4.0);
// d == 4.0
** Not critisising anyone, least of all John. :D

Re: Improve NXC Help File

Posted: 05 Feb 2011, 01:15
by muntoo
Switch the descriptions of UI_VM_RESET1 and UI_VM_RESET2.

Re: Improve NXC Help File

Posted: 07 Feb 2011, 18:44
by afanofosc
I will certainly take these contributions and use them to improve the NXC help. Thanks!

It might also be helpful to email me replacement sample code files (e.g., ex_FUNCTIONNAME.nxc) directly or post them as attachments that I can simply download and rename from .txt to .nxc or something like that.

John Hansen

NXC Example File: "ex_SetLongAbort.nxc"

Posted: 08 Apr 2011, 23:25
by muntoo
[This post provides an example, and also defines the format for future posts of example files.]


Attachment:
ex_SetLongAbort.zip
(554 Bytes) Downloaded 152 times
Notes:
This program example [and variations] can be used in more than one API call example.


[Optional code snippet.]
ex_SetLongAbort.nxc:

Code: Select all

task main()
{
	// Set exit button to end program only if it is pressed for longer than 2 seconds
#ifdef __ENHANCED_FIRMWARE
	SetLongAbort(true);
	// is equivalent to
	SetAbortFlag(BTNSTATE_LONG_PRESSED_EV);
#endif

	while(true)
	{
		ClearScreen();
		// Display on NXT Screen: "Press the exit button longer (for 2 seconds) to exit"
		TextOut(0, LCD_LINE1, "Press the exit", 0);
		TextOut(0, LCD_LINE2, "button longer", 0);
		TextOut(0, LCD_LINE3, "(for 2 seconds)", 0);
		TextOut(0, LCD_LINE4, "to exit.", 0);
		
		
		// Display number of times the user has pressed the exit button (for less than 2 seconds)
		NumOut(0, LCD_LINE8, ButtonPressCount(BTNEXIT), 0);
		
		
		// Wait until user presses and releases exit button before continuing loop
		while(!(ButtonPressed(BTNEXIT, 0)));
		while(ButtonPressed(BTNEXIT, 0));
	}
}

[Optional extra attachment at bottom.]
ex_SetLongAbort.zip
(554 Bytes) Downloaded 152 times