Advertisement Jump to content
Sign in to follow this  
jammer312

Script output error.

This topic is 1772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement

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

fflush(stdout);

Share this post


Link to post
Share on other sites

Here is my function print()

But that thing you said helped. Thanks!

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!