4dm & Practice version

Any questions regarding the practice version are asked and answered here.
Post Reply
Ed Wilson
Posts: 2901
Joined: Tue Oct 11, 2005 7:49 pm

4dm & Practice version

Post by Ed Wilson »

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?
Sam Cech
Posts: 4150
Joined: Fri Oct 14, 2005 12:56 pm
Location: Silverdale, NZ
Contact:

Post by Sam Cech »

ED, I thought you would have had a full license why going to practice?

are all your company licenses on a server?
Cheers
Sam

Tatras Consulting Ltd
www.tatras.co.nz
Ed Wilson
Posts: 2901
Joined: Tue Oct 11, 2005 7:49 pm

Post by Ed Wilson »

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.

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
Sam Cech
Posts: 4150
Joined: Fri Oct 14, 2005 12:56 pm
Location: Silverdale, NZ
Contact:

Post by Sam Cech »

it reads just fine...

Pitty they dont allow single module licenses...
Have never seen the practice version not sure what it does...
But for a user to get a play version for home to learn 4dml any license is too expensive.
Cheers
Sam

Tatras Consulting Ltd
www.tatras.co.nz
Lucien West
Posts: 1115
Joined: Fri Oct 21, 2005 7:51 am

Post by Lucien West »

Using the practice version for macro writing is fine.
The only real issue I think is that printing to the output window is disabled, which makes debuging a lot harder. I ended up using a simple panel to display debug data.
Paul Mashford
Posts: 432
Joined: Tue Oct 11, 2005 11:08 am

Post by Paul Mashford »

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.

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
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"

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 
}
Edit: tweaked the library file so you only need a minimum of 3 calls to get it working
Last edited by Paul Mashford on Tue Jan 11, 2011 9:45 am, edited 1 time in total.
Ed Wilson
Posts: 2901
Joined: Tue Oct 11, 2005 7:49 pm

Post by Ed Wilson »

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!
Ed Wilson
Posts: 2901
Joined: Tue Oct 11, 2005 7:49 pm

Post by Ed Wilson »

Paul,
checking instructions... the first block of code is from file mashy_lib_user_output_window.H right?
the second block of code contains 4 lines to be copied to anything I do..
Paul Mashford
Posts: 432
Joined: Tue Oct 11, 2005 11:08 am

Post by Paul Mashford »

Yes - that's what I called the file, but you can call it whatever you want.

I just edited the code above so that you only need 3 lines in any macros you want to use it.
Ed Wilson
Posts: 2901
Joined: Tue Oct 11, 2005 7:49 pm

Post by Ed Wilson »

nice, thanks very much
Post Reply