Universal Behavior Setting

This forum is currently in read-only mode.
  • I lied, here's another question. 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?

  • 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.

  • I don't see the physics object on the CVS.

  • Oh, its not... humm... well hopefully you can work it out from those functions!

  • Bleh, I'll try.

    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. 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?

  • 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,


    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


    long ExtObject::GetData(int id, void* param)
       int param1;
       string param2;
       switch (id)
          case 1:
             param1 = (int)param;
             return 0;
          case 2:
             param2 = (string)param;
             return 0;
          case 3:
             return param1 + param2;
    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?
  • I'm still not entirely sure I get this. This is what I have in GetData():

    long ExtObject::GetData(int id, void* param)
    	switch (id)
    		case 1:
    			return MASS;
    	return 0;
    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.
  • other way around

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

    long ExtObject::GetData(int id, void* param)
    	switch (id)
    		case 1:
    			return MASS+(int*)param;// for instance, 
    	return 0;
    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 [i]something[/i]
    you have to cast it so it knows what it is
    this way, you can make param any type you want
  • 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.

  • 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.

  • ok

    simple example

    long ExtObject::GetData(int id, void* param)
    	//this would just return the second parameter as an integer....sorry no asterisk needed
    	return (int)param;
    sorry, you don't need any asterisks there, I just compiled an example to make sure this works
    [code:2x70bejr]int* MyIntPointer;  // a pointer to an integer
    not sure if it was my confusion that confused you, 
    or if you're not clear on pointers themselves
    but the way they work is like so:
    int* MyIntPointer; // a pointer to an integer, holds the memory address of an integer
    int MyInt; // I'm pretty sure you know what this is   
    MyIntPointer = &MyInt   // Now MyIntPointer points to the Address of MyInt(& is the address of operator) 
    [code:2x70bejr]MyInt = 3;[/code:2x70bejr]
    *MyIntPointer  is equal to 3
    if I say
    [code:2x70bejr]*MyIntPointer = 5;[/code:2x70bejr]
    MyInt is now equal to 5
    the asterisk before a pointer is called the dereference operator, and makes it so you're basically operating directly on the thing pointed to
    MyIntPointer without the asterisk, is still equal to &MyInt
    hope this made some sense
    Edit:: if you read this before my last edit, read the first part again
    it's (int)param, not int(param)
  • So, if I understand this correctly, your example would merely return the value of the integer that MyIntPointer is pointing to, right? My code:

    	int* MyIntPointer;
    	int MyInt;
    	MyIntPointer = &MyInt;
    	MyInt = 5;
    	stuff = (*i)->GetData(1, MyIntPointer);[/code:jwg63bgz]
    The code I put in the GetData() function is the same as what you have.
    Shouldn't what I have above return 5?  I'm using a Construct expression to access the value of stuff, but it always comes back as a random value between 20 million and 25 million.
  • no

    I bet I said something wrong

    gimme a few minutes

    I'm going to start from an empty sdk

    and tell you exactly

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • k

    this is tested, it returns the right value and everything

    forreal this time

    the exact code you just posted

    and this in getdata will return your param back to you


    long ExtObject::GetData(int id, void* param)
    	int* myint =(int*)param;
    	return *myint;
    sorry for all the wrong answers 
    and to be clear, this also works:
    [code:1nhqf3aj]long ExtObject::GetData(int id, void* param)
    	return *(int*)param;
    you are type casting the void pointer to a int pointer (      (int*)      )
    then you are dereferencing this pointer to get the value of what it's pointing to
    please post back to make sure this worked for you
  • Ooooooooo... it turns out the problem was something entirely seperate from the GetData() code.

    Sorry for all the trouble, and thanks for the help.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)