PDA

View Full Version : Some noob questions



terry422
03-03-2016, 11:16 PM
Like in HUDTextParams&, CBasePlayer@, what do those "&" and "@" mean?

Can't I just declare a variable like "HUDTextParams VariableName", "CBasePlayer VariableName"?

Silencer
04-03-2016, 08:28 AM
& in function header means to hand in a reference instead of a copy: http://www.angelcode.com/angelscript/sdk/docs/manual/doc_script_func_ref.html
@ means object handle: http://www.angelcode.com/angelscript/sdk/docs/manual/doc_script_handle.html (Read this thoroughly)

So yes, you can just declare an object variable, the same way you can just declare an object handle. When a function wants a reference, this usually means that it won't care what you do with it afterwards (as it cannot convert it into a lasting handle), so an object variable is the way to go.

Unfortunately, the documentation misses to explain how to call constructors correctly lol. I imagine it would look something like this:


Thing t1 = Thing(); // Object
t1.DoAThing();
Thing@ t2 = @Thing(); // Object handle; might work without the 2nd @
t2.DoAThing();

A constructor can be called like a function and always has exactly the same name as the type of the object it returns, resulting in these weird looking code lines where the type name appears twice. It's a very common thing to do though.

For simple types that just store a bunch of data directly you often don't need to call the constructor, but you should make sure to set everything then.


Thing t1; // Uninitialized Object
t1.a = 42;
t1.b = 5.2F;
t1.c = "Foo";

terry422
04-03-2016, 09:29 AM
Thank you! I think I totally got it :)

nico
04-03-2016, 09:47 AM
Can't we make a single thread for small AngelScript questions, like the mapping question thread?

Solokiller
04-03-2016, 09:49 AM
Note that you can't use CBasePlayer without an @. You can only work with handles to entities, so using CBasePlayer - or any other entity for that matter - without an @, you'll get a compilation error.

terry422
04-03-2016, 10:19 AM
Can't we make a single thread for small AngelScript questions, like the mapping question thread?
That would be good. I am spamming the helpdesk :D




Note that you can't use CBasePlayer without an @. You can only work with handles to entities, so using CBasePlayer - or any other entity for that matter - without an @, you'll get a compilation error.
Understanding what '@' does, now it is clear why I should put '@' in front. Thanks for pointing it out!