New functions: Pass object as parameter

Get help using Construct 2

Post » Mon Nov 12, 2012 8:35 am

Hey there
I think its (still, maybe in the future?) not possible to do this, but Im asking it cuz you know more than me.

The new functions are really cool and useful, but, for example, if I want to create and object inside a function, I can pass parameters for example, the x or y positions of the newly created object, but, is there any way of passing the object to create in the function too?

As always, thanks for all your help!
B
14
S
4
G
3
Posts: 106
Reputation: 4,792

Post » Mon Nov 12, 2012 12:51 pm

I am currently using strings to check for which object to create in my function. The thing is in any Object-Oriented Languange, it is impossible to pass an object into a function without first creating the object(it will throw exceptions). You can use an enumerator or string and based on that to create the object in the function.
B
7
Posts: 38
Reputation: 683

Post » Mon Nov 12, 2012 2:04 pm

Ummm, ok, thanks man, its logical.

Anyway, I knew I couldnt pass the object itself, but I was thinking if maybe the option of passing a string with the object name would be possible.

So, the solution is to pass a parameter (a number, a string) and make and if statement inside the functions, isnt it? (sorry for this, my english is... well, there is no word to define it xD).
B
14
S
4
G
3
Posts: 106
Reputation: 4,792

Post » Mon Nov 12, 2012 3:38 pm

@msv0001 - that's not quite right, in Construct 2 you can pass instances to functions by passing their UID as a parameter.

@sirLobito - you have to pass a string and check for each possible value of the string in subevents right now - unfortunately you can't create an object by name (due to the fact the obfuscator on export will change object names).
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Mon Nov 12, 2012 4:11 pm

[QUOTE=Ashley]due to the fact the obfuscator on export will change object names[/QUOTE]

Thats totally clarifier, ok, strings as parameters, no prob, thanks :).
B
14
S
4
G
3
Posts: 106
Reputation: 4,792

Post » Tue Nov 13, 2012 11:26 pm

@ashley - But if the instance is not creayed in the first place, there would be no UID. sirLobito was asking for a custom constructor as a function. Correct me if I have misinterpreted the question.
B
7
Posts: 38
Reputation: 683


Return to How do I....?

Who is online

Users browsing this forum: benajad, Braus, R0J0hound, shinkan and 24 guests