more questions (all will go here)

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

Post » Thu May 28, 2009 4:43 pm

hi again, k, having trouble creating an object

I'll show what I've done, maybe you can catch a mistake, or tell me what I'm missing
there's some other less related stuff in there, but it involves extracting parameters or some other likely problem spot:
[code:rqvp7l0h]ADDPARAM(PARAM_OBJECT, "TypeA", "Choose the a TypeA object to initialize the pointer.");
ADDACT("InitPointer", "Initialization", "Initialize Pointer(%o)", &ExtObject::aInitializePointer, "InitializePointer", 0);

////////////////////////////////////

long ExtObject::aInitializePointer(LPVAL params)
{
pTypeAPointer = params[0].GetObjectParam(pRuntime);
return 0;
}
//////////////////////////////////////////////////////////////

ADDPARAM(PARAM_VALUE, "Object Type", "Choose which object to create");
ADDPARAMDEF(PARAM_VALUE, "Layer", "Layer name or number, to create the object on.", "1");
ADDACT("Create Object", "Creation", "CreateObject", &ExtObject::aCreateObject,"hh",0);

/////////////////////////////////////////////////////////////////////

long ExtObject::aCreateObject(LPVAL params)//returns object pointer
{
CRunLayer* pLayer = params[1].GetLayerParam(pRuntime, pLayout);
if (params[0].GetInt() == 0)
{ObjectIndex[index]=pRuntime->CreateObject(pTypeAPointer,pLayer->number, pLayout);}
}[/code:rqvp7l0h]

EDIT, sorry, this may help:
[code:rqvp7l0h] CRunObject* ObjectIndex[500];
int index;
CRunObjType* pTypeAPointer;[/code:rqvp7l0h]
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Thu May 28, 2009 4:54 pm

I've no idea what this code is meant to be doing, but some quick observations:
- Don't use C++ terminology in events (avoid referring to pointers or other programming terms unless they are truly appropriate)
- %o (letter 'o') in action text is your object icon, not the first parameter - the first parameter is %0 (number zero)
- GetObjectParam, GetLayerParam and many other functions in the SDK are allowed to return NULL eg. if the user types the name of a layer that doesn't exist - always check for NULL pointers
- Why does your 'create object' action define an object type parameter as PARAM_VALUE?

Anyways, there's nothing in this snippet that tells me why it wouldn't work. If you debug the call to pRuntime->CreateObject, what are the values of the parameters?
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,468

Post » Thu May 28, 2009 6:28 pm

thanks ash. I actually didn't know how to use the debugger, until I mentioned to david in chat that I didn't know how to use the debugger, and then he started to tell me, and then disappeared, so I messed around until I got it

and the problem was actually pretty stupid
I was returning a value before my object was created. I got used to the construct functions where you can do that

anyway, as far as the object names and such. yeah. it's all going to be one huge initialize action at the beginning when it's final. it's separated into these actions as I go along, because I want to be able to test all these individual pieces out using triggers and events. so these smaller events are really just for debugging purposes until they work perfectly, and then it will only operate on the internal version

on a side note though:
it really is just initializing pointers. I have one main object that's going to contain pointers to everything in an index. all creation and destruction related to each of the plugins in the engine will go through the main object. when you run the initialize action, the dialog tells you what object type to choose for each parameter, this is how it gets pointers to all the object types it will be able to create.
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Fri May 29, 2009 6:36 pm

I suppose this is more of a c++ question again, and I am looking elsewhere for answers as well.

is it possible/what would be the best way to pass multiple parameters to the *void param to
CallFunction(int id, void* param)

as in CallFunction(SomeInt, *hellothere, 6,"what's up?", "how ya doin?")

most of the time it will be just one type of variable, but I am curious about multiple types
for now I am just calling the function several times, and it saves the params one by one
and then there is a different id value I pass that let's it know when I'm done.

can I pass a struct or an array, and is there a better way?
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Fri May 29, 2009 10:33 pm

I'd say a struct would be the best way.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Tue Jun 02, 2009 5:24 pm

[list=1:2c1hym6h]
[*:2c1hym6h]Can I request certain things on the CVS?

[/*:m:2c1hym6h]
[*:2c1hym6h]Is there a link to download a zip or something of an entire plugin, instead of each file one at a time?

[/*:m:2c1hym6h]
[*:2c1hym6h]Are there functions built into EditTime, or CRunObject that allow you to load and access file information at edittime, or would I have to do that from scratch?
Specifically what I'd like to do is save a list of strings in a separate editor and then load this file in construct the way you load a sprite, so it's useable at edittime. After loading them into StringArray:

[quote="example code":2c1hym6h]
[color=#008000:2c1hym6h]// StringArray is a holder for the list loaded at edittime, arraysize is int for number of list items[/color:2c1hym6h]
string StringArray[arraysize];

[color=#008000:2c1hym6h]// ExampleString now holds the first item in StringArray[/color:2c1hym6h]
string ExampleString = StringArray[0];

[color=#008000:2c1hym6h]// Append all StringArray items so ExampleString becomes
// "FirstItem|SecondItem|ThirdItem|etc" [/color:2c1hym6h]
for ([color=#0040FF:2c1hym6h]int[/color:2c1hym6h] i=1, i<arraysize,i++)
{
ExampleString = ExampleString + [color=#BF0000:2c1hym6h]"|"[/color:2c1hym6h] + StringArray[i];
}

[color=#008000:2c1hym6h]//use ExampleString to create enum for parameter list[/color:2c1hym6h]
ADDPARAMCOMBO([color=#BF0000:2c1hym6h]"Example"[/color:2c1hym6h], [color=#BF0000:2c1hym6h]"This is just an example."[/color:2c1hym6h],ExampleString.c_str());
ADDACT([color=#BF0000:2c1hym6h]"My action"[/color:2c1hym6h],[color=#BF0000:2c1hym6h] "My category"[/color:2c1hym6h], [color=#BF0000:2c1hym6h]"Example action (%0)"[/color:2c1hym6h], &ExtObject::aMyAction, [color=#BF0000:2c1hym6h]"MyAction"[/color:2c1hym6h], 0);[/quote:2c1hym6h]
so basically, you could save a list of things to a file in a separate editor, and then load each item into StringArray. When you go to use MyAction in construct, your parameter list would be determined by that file. Are there any functions built into the SDK for loading and stepping through files, or would I have to do the FileIO from scratch?

[/*:m:2c1hym6h]
[*:2c1hym6h]I don't need the whole plugin, but could someone please paste the ENUM from mousekeyboard, the one that let's you choose leftclick,rightclick,a,b,c,TAB,etc... for OnKeyPressed. It would be very helpful, and save me alot of tedium

[/*:m:2c1hym6h]
[*:2c1hym6h]I only recently learned about defining macros from the illustrious David, but I don't understand this statement:
[quote="internal.hpp":2c1hym6h][color=#0040FF:2c1hym6h]#define[/color:2c1hym6h] ADDPARAMCOMBO(n, d, v)[/quote:2c1hym6h]
I thought it worked something like:
[quote:2c1hym6h][color=#0040FF:2c1hym6h]#define[/color:2c1hym6h] ADDPARAMCOMBO(n, d, v) DoFunction(1,n,d,v,"stuff")[/quote:2c1hym6h]
when it doesn't have a second item, what is getting defined as?[/*:m:2c1hym6h][/list:o:2c1hym6h]

Thanks alot guys as always. Things are moving along very nicely thanks to all the help from all of you.
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Tue Jun 02, 2009 11:45 pm

1. I don't understand. What do you mean?
2. Checkout the plugins module with a proper CVS client like TortoiseCVS or SmartCVS.
3. You can just use the ordinary C runtime functions (fopen etc) to access the disk. You can put any code you like in the DefineACES() function, so what you want to do is possible.

4.
[code:2i1xmlg8]struct ControlTableEntry {
int vk;
const char* name;
};

ControlTableEntry keyTable[] = {
{VK_LBUTTON, "Left mouse button"},
{VK_MBUTTON, "Middle mouse button"},
{VK_RBUTTON, "Right mouse button"},
{VK_TAB, "Tab"},
{VK_RETURN, "Enter"},
{VK_SHIFT, "Shift"},
{VK_LSHIFT, "Shift (left)"},
{VK_RSHIFT, "Shift (right)"},
{VK_CONTROL, "Control"},
{VK_LCONTROL, "Control (left)"},
{VK_RCONTROL, "Control (right)"},
{VK_MENU, "Alt"},
{VK_LMENU, "Alt (left)"},
{VK_RMENU, "Alt (right)"},
{VK_PAUSE, "Pause"},
{VK_ESCAPE, "Escape"},
{VK_SPACE, "Space"},
{VK_HOME, "Home"},
{VK_END, "End"},
{VK_UP, "Up arrow"},
{VK_DOWN, "Down arrow"},
{VK_LEFT, "Left arrow"},
{VK_RIGHT, "Right arrow"},
{VK_INSERT, "Insert"},
{VK_DELETE, "Delete"},
{'0', "0"},
{'1', "1"},
{'2', "2"},
{'3', "3"},
{'4', "4"},
{'5', "5"},
{'6', "6"},
{'7', "7"},
{'8', "8"},
{'9', "9"},
{'A', "A"},
{'B', "B"},
{'C', "C"},
{'D', "D"},
{'E', "E"},
{'F', "F"},
{'G', "G"},
{'H', "H"},
{'I', "I"},
{'J', "J"},
{'K', "K"},
{'L', "L"},
{'M', "M"},
{'N', "N"},
{'O', "O"},
{'P', "P"},
{'Q', "Q"},
{'R', "R"},
{'S', "S"},
{'T', "T"},
{'U', "U"},
{'V', "V"},
{'W', "W"},
{'X', "X"},
{'Y', "Y"},
{'Z', "Z"},
{VK_BACK, "Backspace"},
{VK_NUMPAD0, "Num pad 0"},
{VK_NUMPAD1, "Num pad 1"},
{VK_NUMPAD2, "Num pad 2"},
{VK_NUMPAD3, "Num pad 3"},
{VK_NUMPAD4, "Num pad 4"},
{VK_NUMPAD5, "Num pad 5"},
{VK_NUMPAD6, "Num pad 6"},
{VK_NUMPAD7, "Num pad 7"},
{VK_NUMPAD8, "Num pad 8"},
{VK_NUMPAD9, "Num pad 9"},
{VK_ADD, "Num pad Add"},
{VK_SUBTRACT, "Num pad Subtract"},
{VK_MULTIPLY, "Num pad Mulitply"},
{VK_DIVIDE, "Num pad Divide"},
{VK_DECIMAL, "Num pad Decimal"},
{VK_F1, "F1"},
{VK_F2, "F2"},
{VK_F3, "F3"},
{VK_F4, "F4"},
{VK_F5, "F5"},
{VK_F6, "F6"},
{VK_F7, "F7"},
{VK_F8, "F8"},
{VK_F9, "F9"},
{VK_F10, "F10"},
{VK_F11, "F11"},
{VK_F12, "F12"},
{-1, ""},
};[/code:2i1xmlg8]

5. It might help you to buy a C++ reference book or something like that to answer your questions about the language. #define with nothing after it means the given statement is removed (it is defined as nothing). Since you probably looked up its definition in the runtime configuration, and the runtime doesn't care about parameter definitions, it is simply removed. However, the IDE needs to know about parameters, so in the release configuration it is defined as a call to a function.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,468

Post » Wed Jun 03, 2009 12:17 am

[quote="Ashley":2ajiucmm]1. I don't understand. What do you mean?[/quote:2ajiucmm]
Can I request a certain plugin module that isn't already on the CVS, like Mouse/Keyboard? I don't need Mouse/Keyboard, or anything specifically at the moment, but just curious if that's an option


[quote:2ajiucmm]2....5. [/quote:2ajiucmm]
Thanks you very much ashley, and I will be getting myself a C++ ebook, as per your recommendation.
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Wed Jun 03, 2009 2:35 am

is there a function to translate a string into an expression?
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Thu Jun 04, 2009 9:01 am

What do you mean?
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

PreviousNext

Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests