Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 pbody2012   Members   -  Reputation: 115

Like
0Likes
Like

Posted 01 March 2013 - 02:57 PM

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;
} 

 

 



Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 01 March 2013 - 05:31 PM

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

#3 pbody2012   Members   -  Reputation: 115

Like
0Likes
Like

Posted 01 March 2013 - 05:36 PM

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.



#4 pbody2012   Members   -  Reputation: 115

Like
0Likes
Like

Posted 01 March 2013 - 05:37 PM

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



#5 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 01 March 2013 - 05:51 PM

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

#6 pbody2012   Members   -  Reputation: 115

Like
0Likes
Like

Posted 01 March 2013 - 06:12 PM

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



#7 pbody2012   Members   -  Reputation: 115

Like
0Likes
Like

Posted 01 March 2013 - 06:58 PM

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?



#8 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 02 March 2013 - 08:54 AM

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

#9 pbody2012   Members   -  Reputation: 115

Like
0Likes
Like

Posted 02 March 2013 - 12:47 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS