4dm & Practice version
4dm & Practice version
Given the limitation of the practice version in not allowing any outputs, is it suitable to hack/learn 4dm on?
Aside from string edits which it shold be OK with, Im only interested in output to output window, will it fly?
Aside from string edits which it shold be OK with, Im only interested in output to output window, will it fly?
happen to be starting with C for dummies and porting what Im trying to learn.. One of the issues is trying to come up with examples that are meaningful yet do-able, thanks for an example Sam. Compile this (c) to see what Im trying to avoid.
it looks better in Codeblocks
Code: Select all
// where is that ^&%$ dongle now? dongle.c
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char wtf;
char sucker[20];
printf("Where is the flippin 12d dongle?: \n");
printf("For CAR, select c, for WORK, select w, for LOST, select l \n\n");
scanf("%c",&wtf);
if(wtf=='c')
{
printf("You got a lift to work today remember!");
}
if(wtf=='w')
{
printf("So here you are, kids in bed, ready to go and YOU left the flippin dongle at work. \n");
printf("Idiot!");
}
if(wtf=='l')
{
printf("Who left the company recently? \n");
scanf(sucker);
printf("Yeah, why not blame %s, I'm sure %s borrowed it right?\n\n",sucker,sucker);
}
return (0);
}
it looks better in Codeblocks
-
- Posts: 1131
- Joined: Fri Oct 21, 2005 7:51 am
-
- Posts: 439
- Joined: Tue Oct 11, 2005 11:08 am
You can do everything in the practice that you can do in the full version apart from writting out files or printing to the output window. I used to do the same as Lucien, just create a dummy panel.
But this should do what you want. I've only tested on the full version but should work on practise version. It just mimicks an output window by using a dummy panel.
Start by saving this file to a directory where you will save includes. Dont be too concerned with trying to understand what it's doing if your just starting out.
Now for any macros you want to play around with in the practice version just create them as such. The lines with comments are the ones you will need to activate the "user output window"
Edit: tweaked the library file so you only need a minimum of 3 calls to get it working
But this should do what you want. I've only tested on the full version but should work on practise version. It just mimicks an output window by using a dummy panel.
Start by saving this file to a directory where you will save includes. Dont be too concerned with trying to understand what it's doing if your just starting out.
Code: Select all
#ifndef MASHY_LIB_USER_OUTPUT_WINDOW_INCLUDED
#define MASHY_LIB_USER_OUTPUT_WINDOW_INCLUDED
// Include this file in your macro to print to a dummy output window
//change these to control the appearance of the output window
#define USER_WINDOW_LINES 25
#define USER_WINDOW_WIDTH 50
#define USER_WINDOW_POSITION_X 500
#define USER_WINDOW_POSITION_Y 50
#define USE_12D_OUTPUT_WINDOW_IF_NOT_PRACTICE 0
//global variable, these are some variables for a user defined output window
{
Panel output_window;
Text_Edit_Box output_window_text_box;
Message_Box output_window_message;
Dynamic_Text output_window_text;
Integer output_window_exists;
}
Integer split_multiline_text(Text text, Dynamic_Text &dt){
//returns the number of lines
Integer count = 0;
Integer len = Text_length(text),start=1,end;
for(Integer i=1;i<=len;i++){
Integer c1;
Get_char(text,i,c1);
if(c1=='\n'){
end = i-1;
Text t = Get_subtext(text,start,end);
Append(t,dt);
start = i+1;
count++;
continue;
}
}
if(start < len){
Append(Get_subtext(text,start,len),dt);
count++;
}
return(count);
}
void clear_console(){
Null(output_window_text);
Set_data(output_window_text_box,"");
}
void create_output_window(){
output_window = Create_panel("User output window");
output_window_message = Create_message_box("");
output_window_text_box = Create_text_edit_box("Text edit box",output_window_message,USER_WINDOW_LINES);
Set_width_in_chars(output_window_text_box,USER_WINDOW_WIDTH);
Append(output_window_text_box,output_window);
Show_widget(output_window,USER_WINDOW_POSITION_X,USER_WINDOW_POSITION_Y);
}
void debug_print(Text text){
#if USE_12D_OUTPUT_WINDOW_IF_NOT_PRACTICE
if(Is_practise_version()){
#endif
if(output_window_exists!=1){
create_output_window();
output_window_exists=1;
}
Dynamic_Text dt;
if( split_multiline_text(text,dt) ){
Append(dt,output_window_text);
Set_data(output_window_text_box,output_window_text);
}
#if USE_12D_OUTPUT_WINDOW_IF_NOT_PRACTICE
}else{
Print(text);Print();
}
#endif
}
void wait_to_close_output_window(){
Integer id;
Text cmd,msg;
while(1){
Wait_on_widgets(id,cmd,msg);
if(cmd == "Panel Quit")return;
}
}
#endif
Code: Select all
#include <mashy_lib_user_output_window.H> //need to include the file from the library
void main(){
Real radius = 10;
Real area = Pi() * Pow(radius,2);
debug_print(To_text(area,3)); //use debug_print() instead of Print()
wait_to_close_output_window(); //need this line to stop the output window from shutting down before we get a chance to read it
}
Last edited by Paul Mashford on Tue Jan 11, 2011 9:45 am, edited 1 time in total.
Thanks Guys, as Lucien says, having the output window not show any output will kind of kill off this idea, unless one of the 4dm tutes is how to add a simple panel to display debug data...... not feeling confident about that will be flying fairly blind most times I suspect .....
Hopefully i dont have to enter 'l' into the app above too many times!
Edit, Paul hit send before I did. THANKS!
Hopefully i dont have to enter 'l' into the app above too many times!
Edit, Paul hit send before I did. THANKS!
-
- Posts: 439
- Joined: Tue Oct 11, 2005 11:08 am