Script output error.

Started by
1 comment, last by jammer312 10 years, 1 month ago

I finally completed adding as to project but now I facing one issue.



void main()
{
print("HOOORAY\n");
print("TEST");
}

Here is code from .as file.


bool runmodule(string modulename)
{
	// Find the function that is to be called.
	asIScriptModule *mod = engine->GetModule(modulename.c_str());
	asIScriptFunction *func = mod->GetFunctionByDecl("void main()");
	if( func == 0 )
	{
	  // The function couldn't be found. Instruct the script writer
	  // to include the expected function in the script.
	  printf("The script must have the function 'void main()'. Please add it and try again.\n");
	  return false;
	}
	// Create our context, prepare it, and then execute
	asIScriptContext *ctx = engine->CreateContext();
	ctx->Prepare(func);
	int r = ctx->Execute();
	if( r != asEXECUTION_FINISHED )
	{
	  // The execution didn't complete as expected. Determine what happened.
	  if( r == asEXECUTION_EXCEPTION )
	  {
	    // An exception occurred, let the script writer know what happened so it can be corrected.
	    printf("An exception '%s' occurred. Please correct the code and try again.\n", ctx->GetExceptionString());
	  }
	}
	return true;
}

It's function for running modules.


#include "Graphics/Drawing.h"
#include "Events/Events.h"
#include <SDL/SDL.h>
#include "AngelScript/AS.h"
#include "Files/AS_cfgs.h"
//(a&^b)
int main()
{
	if(SDL_Init(SDL_INIT_EVERYTHING)<0)
	{
		printf("Error");
		return -1;
	}
	printf("Initialization completed\n");
	SDL_Surface * screen = SDL_SetVideoMode(320,320,16,SDL_HWSURFACE | SDL_RESIZABLE);
	if(!screen)
	{
		printf("Cannot create screen\n");
		return -1;
	}
	printf("Screen created\n");
	SDL_WM_SetCaption("Hello World",NULL);
	show(screen);
	if(!as_init())
	{
		return -1;
	}
	if(build_modules_from_cfg())
		{
	//		printf("%s\n","Modules built" );
		}
	else
		{
	//		printf("%s\n","Invalid file or containing data" );
		}
		printf("%s\n","--------------------------" );
			as_execute();
	while(!APP_quit)
	{
	//SDL_Delay(10);
	getevent();
	}
	SDL_Quit();
	return 1;
}

And here is main.cpp that runs everything.

Issue is that script prints only "HOOORAY"

But when I close SDL window it prints "TEST".

Is there any ways to fix it? I don't even know what can cause it.

Advertisement

Where is your C++ print() that the script print is calling? Maybe it needs something like:


fflush(stdout);

Here is my function print()

But that thing you said helped. Thanks!


void print(const string &in)
{
	printf("%s",in.c_str());
}

This topic is closed to new replies.

Advertisement