Universal Behavior Setting

Forum for plugin, effect and behavior programmers. Please use the Help & Support forum for help using Construct.

Post » Sun Jun 21, 2009 11:53 pm

I lied, here's another question. :P How would I go about making a universal setting for a behavior, for example, something like the physics behavior where the gravity parameter is universal across all objects with physics?
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Mon Jun 22, 2009 12:45 am

Look at the Physics object source on CVS. At edittime you can use SetGlobalKey/SetLayoutKey to store named global data (a four byte void*). If the 'save' parameter is true, the data is saved to the .cap and also exported to the runtime when previewing. VRuntime also has set/get global/layout key functions, which can then retrieve the data.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon Jun 22, 2009 2:34 am

I don't see the physics object on the CVS. :?
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Mon Jun 22, 2009 3:07 am

Oh, its not... humm... well hopefully you can work it out from those functions!
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon Jun 22, 2009 4:03 am

Bleh, I'll try. :P

By the way, I have another question and I'm sicking of making new threads, so I'm going to ask it here. How does the GetData() function work? I know lucid asked about it, then he figured it out, and then he didn't tell anybody what he did. :P I know you have to specify the values to return inside the function and assign what seems to amount to an access number to it.
Thing is, I don't know what the second parameter when calling it is supposed to be. So, how would I use this to access a value from one of the objects that my vector(from the other threads) is pointing to?
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Mon Jun 22, 2009 4:26 am

you can pass anything for the void parameter, so
you have to cast the void* parameter to whatever you need it to be
like (int)param
or (string)param

GetData() and CallFunction() are exactly the same as far as I can tell. There are two of them for logic and readablility

pretty straightforward so far,


however,
if you happen to need more than one parameter there are three ways I thought of that would work

I never tried it but I believe you should be able to make a struct in both the calling function and in the body of GetData(), and cast it to that if you need multiple parameters


alternatively, you can pass the parameter (this)
and cast it to *CRunObject
then you can do param->GetData(whatever) and have GetData functions in the calling object that will return the parameters you need one by one

and lastly, you can just set up multiple functions that append all the needed parameters
like
[code:1pl9i59i]long ExtObject::GetData(int id, void* param)
{
int param1;
string param2;

switch (id)
{
case 1:
{
param1 = (int)param;
return 0;
break;
}

case 2:
{
param2 = (string)param;
return 0;
break;
}
case 3:
{
return param1 + param2;
break;
}
}[/code:1pl9i59i]

btw, if you're on right now, you should go to chat
we can be plugin code buddies

edit:: and if it's not top secret, may I ask what type of plugin you're developing?
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Mon Jun 22, 2009 5:12 am

I'm still not entirely sure I get this. :? This is what I have in GetData():

[code:vw3xcad2]long ExtObject::GetData(int id, void* param)
{
switch (id)
{
case 1:
return MASS;
}
return 0;
}[/code:vw3xcad2]
This is where I try and retrieve something:

[code:vw3xcad2]stuff += (*i)->GetData(1, (float)param);[/code:vw3xcad2]
Thing is, it throws a fit about how "param" is undeclared, and how it can't convert from "void *" to "float" and stuff. :? I'm not exactly sure what you were getting out, so I'm getting kind of confused here.

The plugin I'm working on is a gravitation behavior. You put it on objects and you can set weather objects are attractors and/or satellites. Kind of like a much more advanced version of my orbiter behavior. :)
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Mon Jun 22, 2009 5:21 am

other way around

in GetData(): if you need param for something that's where you cast it

[code:2tctjxno]long ExtObject::GetData(int id, void* param)
{
switch (id)
{
case 1:
return MASS+(int*)param;// for instance,
}
return 0;
}[/code:2tctjxno]
This is where you would retrieve something:

[code:2tctjxno]stuff += (*i)->GetData(1, *MyInt);[/code:2tctjxno]

I may have messed up the asterisks in the return MASS line in order for it to add correctly
I'm pretty new to pointer notation, but the basic idea is
that void* is a pointer to something
you have to cast it so it knows what it is
this way, you can make param any type you want
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Mon Jun 22, 2009 3:22 pm

I've fiddled around with it the way you show, changing the asterisks and stuff, but I can't get it to work. :? That, and i don't know what's up with *MyInt. Do you have a working example of the code I could look at? I have trouble grasping this stuff alot of the time.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Mon Jun 22, 2009 3:44 pm

GetData() is nothing more than a general-purpose plugin-defined function that other plugins can call to get data or perform actions specific to that plugin. 'id' is intended to determine what to do, and the void* param is simply four bytes of data to pass as a parameter. The return value is so the callee can get data back from the call (or it can write out to the pointer 'param').

If the basic syntax is confusing you, you might want to go over a C++ tutorial or book again some time.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Next

Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests