Game Development Community

Console method to script

by Steve D · in Technical Issues · 05/09/2007 (9:31 am) · 8 replies

Hi all, I'm having a little problem and I can't figure out what I'm doing wrong.

I made a simple c++ class called inventory which compiles fine. I have a variable called shotgunshells which reads fine from script. But in script when I use either of the two functions I have defined I get an error.

In script I have -

echo(%obj.inventory.shotgunshells);

That echo's the value just fine so I am sure I have the class object correctly.

%obj.inventory.IncreaseShotgun(2);

This gives me the error - Unknown command IncreaseShotgun. Object (1490) Inventory -> sim object

I also have a function called DecreaseShotgun and I get the same error.

// c++ class member functions

ConsoleMethod(Inventory, IncreaseShotgun, void, 2,0,"")
{
object->IncreaseShotgun(dAtoi(argv[2]));
}

ConsoleMethod(Inventory, DecreaseShotgun, S32, 2,2,"")
{
return object->DecreaseShotgun();
}

I'm sure I'm missing something simple, can anyone tell me where I'm going wrong?

#1
05/09/2007 (9:44 am)
Is %obj.inventory created via %obj.inventory = new Inventory() or something similar ?
try this: echo(%obj.inventory.getClassName()); - if it's not "Inventory" then there's yr problem.
#2
05/09/2007 (9:47 am)
Yes that's how I make a new inventory object and I just did the echo statement and it comes back as Inventory.
#3
05/09/2007 (9:48 am)
And also fyi I followed the steps in creating a simple simobject here

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5516

And just added in my own functions
#4
05/09/2007 (9:54 am)
Hm. that's strange.

it might be that "0" in ConsoleMethod(Inventory, IncreaseShotgun, void, 2,0,"").
that should be a "2".
altho you say DecreaseShotgun() works, so that may not be it.

also not that you're there yet,
but you'll want to use argv[1], not argv[2].
(argv[1] is the second argument, because argv[0] is the first)

well,
this sounds stupid,
but are you sure your console methods have compiled ?
try adding "#error this is an error" into one of them and recompiling.
if the compile succeeds, something is wrong.

try doing %obj.inventory.dump(); - that will list all the methods of the object. are your custom FNs in there ?
#5
05/09/2007 (10:04 am)
DecreaseShotgun doesn't work either

I made that other change and still no difference. Yes I'm positive I'm compiling it correctly.
#6
05/09/2007 (10:30 am)
Are you sure you're running against the right binary ?
sometimes i'll be compiling say release but testing agains debug or something.
#7
05/09/2007 (1:03 pm)
I'm positive because the variable shotgunshells is correctly displaying the value I assigned to it within the class constructor.
#8
05/09/2007 (1:24 pm)
Huh. well i'm out of ideas. anyone else ?