• Advertisement

Hardguy

Member
  • Content count

    279
  • Joined

  • Last visited

Community Reputation

244 Neutral

About Hardguy

  • Rank
    Member
  1. Giver class member variables start values.

    [quote name='Andreas Jonsson' timestamp='1337090424' post='4940409'] Should someone like to implement the feature for me I'd gladly add it to the library though. [/quote] Oh, you so sneaky ;) Do you mean implement in a something like script_builder? Or directly in the lib? If in script_builder I could give that a go, but not sure how to go about., so any pointers might persuade me to do it
  2. I am wondering if there is anyway to do something like: [code]class cMyClass { int mlCount=0; } [/code] or if that is not possible, some way at least let all the basic types (float, int, etc) be 0 from start? The only way I can think of now is to iterate all of the member vars upon creating a class object and then zeroing them. Is there any simpler way to achieve this or even better to do something like the sample code above. When scripting, it is often very convenient to declare member variables near the method where they are used, and thus it can be cumbersome to always go to the construct to init them. For instance: [code]class cMyClass { .... int mlNumOfSlugAttacks=0; SlugAttacksPlayer() { mlNumOfSlugAttacks++; if(mlNumOfSlugAttacks>3) DoSomething(); } ... }[/code] Any ideas on ways to achieve this would be very helpful! Perhaps I am missing some feature that is already in the language?
  3. What kind of sorcery is this! Classes in Amnesia Script! More seriously, Amnesia use AngelScript very simplistically and we never used classes when creating the game. Now I got kind of curious on what you are using it for, care to share? [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
  4. Late reply [quote name='Andreas Jonsson' timestamp='1326489145' post='4902453'] Are you by any chance copying the ref counter too? That mustn't be done as it would screw up the memory management. [/quote] Ah yes! That was the problem! Thanks!
  5. Problem with shared keyword

    Note that that code does not make any sense to use, and it was just me setting "shared" where it was not really needed. Still it might be something worth looking into, as it is still a bug? Or perhaps something that the compiler should report as invalid?
  6. Problem with shared keyword

    I made a bunch of testing now and found out my code example was wrong! Here is how to reproduce: [code]shared class iTest_Interface { void HelpFunc(){} int mlBaseData; } //----------------------------------- class cTest : iTest_Interface { cTest() { } void DoSomething() { Print(" Inside DoSomething 1\n"); } }[/code]
  7. And that test produces a memory leak.
  8. I only use [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]asOBJ_REF as flag.[/left][/size][/font][/color] [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]Here are the factories:[/left][/size][/font][/color] [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][code][/left][/size][/font][/color]RegisterFactory("", Factory_cBoundingVolume_Default); RegisterFactory("const cVector3f &in avMin, const cVector3f &in avMax", Factory_cBoundingVolume_MinMax); RegisterFactory("const cVector3f &in avSize", Factory_cBoundingVolume_Size);[/code] Here is the script: [code]void main() { cBoundingVolume @pBV = GetBV(); cBoundingVolume copyBV = pBV; Print("Done!\n"); }[/code] Here is the bytecode output: [code]void main() Temps: 2, 10 Variables: 001: cBoundingVolume@ pBV 003: cBoundingVolume copyBV 002: cBoundingVolume {noname} 010: tString {noname} 0 0 * PUSH 10 - 3,2 - 1 10 * SUSPEND 2 10 * VarDecl 0 2 10 * CALLSYS 4125 (cBoundingVolume@ GetBV()) 4 10 * STOREOBJ v2 5 10 * PshVPtr v2 6 11 * PSF v1 7 12 * REFCPY 0x3dc6598 9 11 * FREE v2, 64775576 11 11 * POP 1 - 4,2 - 12 10 * SUSPEND 13 10 * VarDecl 1 13 10 * ChkNullV v1 14 10 * VAR v1 15 11 * CALLSYS 218 (cBoundingVolume@ _beh_2_()) 17 11 * STOREOBJ v3 18 11 * PshVPtr v3 19 12 * GETOBJREF 1 20 12 * CALLSYS 227 (cBoundingVolume& cBoundingVolume::opAssign(const cBoundingVolume&in)) - 6,2 - 22 10 * SUSPEND 23 10 * STR 0 (l:6 s:"Done! ") 24 12 * PSF v10 25 13 * CALLSYS 351 (tString _string_factory_(const int, const uint8&)) 27 10 * ObjInfo v10, 1 27 10 * PSF v10 28 11 * CALLSYS 4123 (void Print(tString&in)) 30 10 * PSF v10 31 11 * CALLSYS 343 (void tString::_beh_1_()) - 7,2 - 33 10 * ObjInfo v10, 0 33 10 * SUSPEND 34 10 * FREE v3, 64775576 36 10 * FREE v1, 64775576 38 10 * 0: 38 10 * RET 0[/code]
  9. Problem with shared keyword

    When using the shared keyword for an interface a class uses, I can not longer reload it properly. Script code is something like [code]shared interface iMyInterface { void MyFunc(); } class cMyClass : iMyInterface { void MyFunc() { //Do stuff } }[/code] If I reload this script then calling MyFunc() from C++ code no longer works. The way I reload is to use DiscardModule() in script engine and then create it from scratch (just like I did the first time it was created). If I remove "shared" from iMyInterface declaration, all works fine.
  10. Quickly summarized, the problem is that when I assign a value from a c++ created object (handle) to a script created one, memory is not freed properly. The code looks like this: [code]cBoundingVolume@ pCharBV = GetBoundingVolume(); cBoundingVolume bvCopy = pCharBV;[/code] This does not release the memory of cBoundingVolume (I am not sure of the exact script place the memory allocation takes place but can try and find out if needed) and I get a memory leak. However,this code works just fine: [code]cBoundingVolume@ pCharBV = GetBoundingVolume(); cBoundingVolume bvCopy;[/code] GetBoundingVolume is a c++ function and has this declartion: [code]cBoundingVolume@+ GetBoundingVolume()[/code] I am guessing that the problem might be that I am not declaring the copy operator correctly? Currently it looks like this: [code]RegisterOperator("cBoundingVolume &opAssign(const cBoundingVolume &in)", asMETHODPR(cBoundingVolume, operator =, (const cBoundingVolume &), cBoundingVolume &) );[/code] Do I need to do something different for it to work? (as in increasing a user count in cBoundingVolume?) I was not sure exactly what code is needed, so just say if you need to see more in order to locate the problem!
  11. (Late answer, got no e-mail notification that I got a reply...must check settings) So what I do is simply: [code]shared class cMyClass {}[/code] and [code]shared interface cMyClass {}[/code] for anything that will be used by several modules?
  12. I have gotten a exception when using an enum across several modules. Here is the setup (in simplified form): [b]interface.code:[/b] [code] enum eMyEnum { eFirst, //.... } interface iMyInterface { void SomeKindOfAction(eMyEnum aData); }[/code] [b]implemented.code:[/b] [code]#include "interface.code" class cMyClass : iMyInterface { void SomeKindOfAction(eMyEnum aData) { ///... } }[/code] [b]main.code:[/b] [code]#include "interface.code" void DoSomething() { //GetMyClass is implemented in C++ and returns cMyClass as implemented in "implemented.code" iMyInterface @pData = GetMyClass(); pData.SomeKindOfAction(eFirst); } [/code] One module is built from "implemented.code" and one from "main.code". When running DoSomething() the script returns that an exception has occured when calling the line: pData.SomeKindOfAction(eFirst); If I change to eMyEnum to int all works fine and there is no exception. Am I doing something wrong here or might this be a bug, or just a limitation of the script? Bonus questions: 1) If this is an error, does this apply to classes aswell? (Do I need to use interfaces as params?) 2) If enums cannot be shared across modules, is it possible to do: [code]int x=0; eMyEnum e = x;[/code] Some how?
  13. ExecuteString in Object?

    Is it possible to call a method in an object by passing a string, like is done with ExecuteString in scripthelper.cpp? I check the code and from what I can see it is not possible to extend to include object methods as that requires knowledge of the actual object pointer (which [url="http://www.angelcode.com/angelscript/sdk/docs/manual/classas_i_script_module.html#1258d7cfeed965f36ba312beeb49e81c"]CompileFunction[/url] does not). So is this possible in some other way? And if so, how do I go about? Reason for wanting this, is because it is a more secure way for script to call methods in other modules.
  14. ExecuteString in Object?

    Is it possible to call a method in an object by passing a string, like is done with ExecuteString in scripthelper.cpp? I check the code and from what I can see it is not possible to extend to include object methods as that requires knowledge of the actual object pointer (which [url="http://www.angelcode.com/angelscript/sdk/docs/manual/classas_i_script_module.html#1258d7cfeed965f36ba312beeb49e81c"]CompileFunction[/url] does not). So is this possible in some other way? And if so, how do I go about? Reason for wanting this, is because it is a more secure way for script to call methods in other modules.
  15. Another thing I found. Need to add: [code] //Skip any white spaces in case meta data follows: t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); while(t == asTC_COMMENT || t == asTC_WHITESPACE) { pos += len; t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len); } [/code] At the end of the section that checks handles the start of class, ie the one that starts with: [code]if( modifiedScript.substr(pos,len) == "class" ) {[/code] Sorry for spamming changes, but seemed so small that was not worth to upload the entire code.
  • Advertisement