[c] non constant int

Started by nathmatt, August 01, 2011, 02:30:10 pm

Previous topic - Next topic

nathmatt

how do i return a non constant int when i just use int it gives me an error  case label does not reduce to an integer constant  here is the portion of the code im have issues with

DLLIMPORT int code (const char s)
{
   switch ( s )
   {
   case "string1":
   return 1;
   break;
   case "string2":
   return 2;
   break;
   default:
   return 0;
   break;
   }
}
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


Blizzard

If you mean something like a local variable, you just have to declare it first.

int result = 0;
/* your code here */
return result;
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

nathmatt

August 01, 2011, 03:44:14 pm #2 Last Edit: August 01, 2011, 03:53:54 pm by nathmatt
im trying to send it a string and have it return a number back using the switch statement but since the integer is non constant then it gives me an error

edit i just figured out my problem the switch statement only works on integers and i was trying to use it on a string will just use the if statement then 
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


Blizzard

Oh, right. ._. I forgot that, too. ._.;
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

nathmatt

ok now my dll will not accept a parameter here is the method

DLLIMPORT int code (char s[20])
{
   if (s == "string1"){return 1;}
   if (s == "string2"){return 2;}
   return 0;
}


and im calling it like this

s = Win32API.new('Project1','code','S','I')
s.call('string1')
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


Cremno

August 01, 2011, 05:18:22 pm #5 Last Edit: August 01, 2011, 05:21:52 pm by Cremno
To compare two strings in C you have to use strcmp (string.h) or a similiar function. It returns zero when both strings are identical.
DLLIMPORT int code (char s[]) {
if (!strcmp(s, "string1")) return 1;
if (!strcmp(s, "string2")) return 2;
return 0;
}

Notice the removed 20. Strings in C aren't easy to handle as in other languages. And are you sure about the 'S'? If you use the RGSS it has to be 'P'.

nathmatt

August 01, 2011, 05:24:52 pm #6 Last Edit: August 01, 2011, 06:26:42 pm by nathmatt
it was p thx

edit it fully works now thx
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script