Results 1 to 3 of 3

Thread: Print any variable's content

  1. #1
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts

    Print any variable's content

    I'm currently into debugging my code and I'd like to print any object to console.
    However I cannot distinguish between an array, a struct or an int/float (if I use .size on an int, a compile error is emmitted):

    PHP Code:
    PrintObjectobj )
    {
        
    elem "undefined";

        if( 
    isDefined( array[ ] ) )
        {
            if( 
    isPlayerobj ) )
                
    elem obj.name;
            else if( 
    isStringobj ) )
                
    elem sprintf"\"%\"" obj );
            else 
    // could be int/float or an array or a struct
                
    elem "{object}";
        }

        
    printf"%\n" elem );

    Is there any way to get the type?
    Last edited by serthy; 13th September 2016 at 18:58.

  2. #2
    Corporal voron00's Avatar
    Join Date
    Nov 2014
    Posts
    248
    Thanks
    64
    Thanked 216 Times in 116 Posts
    I beleive getType() is what you are looking for? https://github.com/voron00/libcod/bl...er/gsc.cpp#L89
    sudo apt-get rekt

  3. The Following User Says Thank You to voron00 For This Useful Post:

    serthy (13th September 2016)

  4. #3
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Yup, returns every available gsc type possible

    PHP Code:
    char *stackGetParamTypeAsString(int param) {
        
    aStackElement *scriptStack = *(aStackElement**)getStack();
        
    aStackElement *arg scriptStack param;
        
        
    char *type "UNKNOWN TYPE!";
        switch (
    arg->type) {
            case  
    0type "UNDEFINED"; break;
            case  
    1type "OBJECT"; break;
            case  
    2type "STRING"; break;
            case  
    3type "LOCALIZED_STRING"; break;
            case  
    4type "VECTOR"; break;
            case  
    5type "FLOAT"; break;
            case  
    6type "INT"; break;
            case  
    7type "CODEPOS"; break;
            case  
    8type "PRECODEPOS"; break;
            case  
    9type "FUNCTION"; break;
            case 
    10type "STACK"; break;
            case 
    11type "ANIMATION"; break;
            case 
    12type "DEVELOPER_CODEPOS"; break;
            case 
    13type "INCLUDE_CODEPOS"; break;
            case 
    14type "THREAD_LIST"; break;
            case 
    15type "THREAD_1"; break;
            case 
    16type "THREAD_2"; break;
            case 
    17type "THREAD_3"; break;
            case 
    18type "THREAD_4"; break;
            case 
    19type "STRUCT"; break;
            case 
    20type "REMOVED_ENTITY"; break;
            case 
    21type "ENTITY"; break;
            case 
    22type "ARRAY"; break;
            case 
    23type "REMOVED_THREAD"; break;
        }
        return 
    type;

    timescale 0.01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •