How to pass array<string>& to a function?

Started by
7 comments, last by pbody2012 11 years, 1 month ago

Just as the title says, how do i pass array<string>& to a function?

I have this function defined in anglescript and I have other script functions calling it. However, it is failing to compile with this message: unit-spec.as (5,25) : ERR : Expeted ">" or ","


bool stringInList( array<string>& arg, string s )
{
	for( uint n = 0; n < arg.length(); n++ )
	{
		if( arg[n] == s )
			return true;
	}
	return false;
} 

Advertisement

This is the correct way to declare a function that takes an array reference as input and output. It shouldn't be a problem compiling this. It's possible that you've stumbled on a bug in AngelScript, however I'm not able to recreate any problem with just this script sample.

What version of AngelScript are you using?

Are you using any non-default options in your application, e.g. asEP_ALLOW_UNSAFE_REFERENCES?

Are you using namespaces?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I'm using version 2.26

I am not using any non default options, I have not touched these at all.

I am using a namespace but it is for another piece of code.

This code is in a separate file and it is being included in another file.

I am also not using the repository version. I'd rather not until the next release.

Though you don't want to use the repository version yet, would it be possible for you to just give it a try to see if it fixes the problem you're having? There hasn't been any changes to the interface so it should just be a matter of recompiling your app with the new header (to get the right ANGELSCRIPT_VERSION).

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Ok I will give it a try and let you know what happened.

Ok I found out that I forget to register the array types, so I did that. The function is compiling, however I cant it.

I have the following code that I call the function from:


array<string> gEngineRPMUnits = { "stall-rpm","start-rpm","idle-rpm","redline-rpm","max-rpm" };

string VerifyEngineUnitSpec( string attribute, string unitSpec )
{
	// local
	// string result;
	
	// check for rpm
	if( stringInList(gEngineRPMUnits,attribute) )
	{
		// unit has to be rpm, rps, rad/s
		if( unitSpec!="revolution" )
			return "error";
		else
			return unitSpec;
	}
        return "";
}

Is this valid?

Yes. this is valid code.

Perhaps you could share what problem you're facing? Are you getting compiler errors? Or is the code not behaving as you expect?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I kept getting compiler errors so i decided to toss the code and use a workaround.

This topic is closed to new replies.

Advertisement