1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

[SOLVED] void GetButtonsFor

Discussion in 'Modding Help' started by FunATuns, May 5, 2015.

Thread Status:
Not open for further replies.
  1. FunATuns

    FunATuns Builder Carry Donator

    Messages:
    114
    Hello. I'm trying to make a workshop in which a button appears to turn the fire in the workshop on and off but My code is not working and the workshop is not spawning when I try to build it here is what i have so far:
    Code:
    #include "Requirements.as"
    //#include "ShopCommon.as";
    #include "CheckSpam.as";
    #include "BF_Costs.as";
    
    void onInit( CBlob@ this )
    {
       
        this.getSprite().SetZ(-50);
        this.getShape().getConsts().mapCollisions = false;
        this.addCommandID("Roast");
        this.set_bool( "Roaston", false);
        this.SetLightRadius( 64.0f );
        this.SetLightColor( SColor(255, 255, 240, 171 ) );
        this.SetLight(true);
    }
    
    string isRoaston(CBlob@ this)
    {
       if(this.get_bool("Roaston"))
       {
            return "Turn Roast off";
       }
       else
       {
            return "Turn Roast on";
       }
    }
    void GetButtonsFor(CBlob@ this, CBlob@ caller)
    {
        CBitStream params;
        params.write_u16(caller.getNetworkID());
       
        if(caller.getDistanceTo(this) > 10.0f)
        {
            CButton@ Fire_on = caller.CreateGenericButton( "$mat_wood$", Vec2f(0.0f,1.0f), this, this.getCommandID("Roast"), "bleh", params );
            if(Fire_on != null)
            {
                retrieve_button.SetEnabled(true);
            }
        }
    }
    void onCommand( CBlob@ this, u8 cmd, CBitStream @params )
    {
        CSprite@ sprite = this.getSprite();
        if(cmd == "Roast" && !this.get_bool( "Roaston"))
        {
            this.set_bool( "Roaston" , true);
            sprite.SetAnimation("fire");
           
            this.SetLight(true);
        }
        if else (cmd == "Roast" && this.get_bool( "Roaston"))
        {
            this.set_bool( "Roaston" , false);
            sprite.SetAnimation("default");
            this.SetLight(false);
        }
    }
    Any help is welcome, thank you!
     
  2. Skinney

    Skinney THD Team THD Team Forum Moderator Tester

    Messages:
    468
    There are a couple things to point out in your script.

    On initialization, you're setting light on while at the same time setting the bool for the light off which would lead to unintended functionality.

    You're sending information over the bit stream that you don't use, please use -
    CButton@ CreateGenericButton(const string&in, Vec2f, CBlob@, uint8, const string&in)

    Double check your if statement, if(caller.getDistanceTo(this) > 10.0f). Are you sure you want to create buttons for blobs that are greater than 10.0f away?

    I don't see a type with the reference, retrieve_button.

    Additionally, please include errors and be as descriptive as possible with what is exactly wrong.
     
    Asu likes this.
  3. FunATuns

    FunATuns Builder Carry Donator

    Messages:
    114
    Ok sorry. but Thank you VERY much for replying so quickly.
    Its still not working despite the various fixes, there is no error on the rcon or the server console. The problem is that the workshop is not being created when I click on it in the menu.

    Heres updated code:
    Code:
    #include "Requirements.as"
    //#include "ShopCommon.as";
    #include "CheckSpam.as";
    #include "BF_Costs.as";
    
    void onInit( CBlob@ this )
    {
      
        this.getSprite().SetZ(-50);
        this.getShape().getConsts().mapCollisions = false;
        this.addCommandID("Roast");
        this.set_bool( "Roaston", false);
        this.SetLightRadius( 64.0f );
        this.SetLightColor( SColor(255, 255, 240, 171 ) );
        this.SetLight(false);
    }
    
    string isRoaston(CBlob@ this)
    {
       if(this.get_bool("Roaston"))
       {
            return "Turn Roast off";
       }
       else
       {
            return "Turn Roast on";
       }
    }
    void GetButtonsFor(CBlob@ this, CBlob@ caller)
    {
      
        if(caller.getDistanceTo(this) < 10.0f)
        {
            CButton@ Fire_on = caller.CreateGenericButton( "$mat_wood$", Vec2f(0.0f,1.0f), this, this.getCommandID("Roast"), "bleh");
            if(Fire_on != null)
            {
                Fire_on.SetEnabled(true);
            }
        }
    }
    void onCommand( CBlob@ this, u8 cmd, CBitStream @params )
    {
        CSprite@ sprite = this.getSprite();
        if(cmd == "Roast" && !this.get_bool( "Roaston"))
        {
            this.set_bool( "Roaston" , true);
            sprite.SetAnimation("fire");
          
            this.SetLight(true);
        }
        if else (cmd == "Roast" && this.get_bool( "Roaston"))
        {
            this.set_bool( "Roaston" , false);
            sprite.SetAnimation("default");
            this.SetLight(false);
        }
    }
    I can show you, Im on Funatuns bunnyfection server
     
    Last edited: May 5, 2015
  4. Fernegulus

    Fernegulus Bison Rider

    Messages:
    400
    Something not spawning despite being spawned usually means compilation errors.

    What about the console logs? Can you paste them (KAG/Logs directory, console-[date and time].txt)?
     
  5. FunATuns

    FunATuns Builder Carry Donator

    Messages:
    114
    CRules Command GameplayEvent not found; add it first in onInit()
    ^^^^^^^^ This error was constantly popping up
    I wonder if that is the problem, do you know anything about that error?

    Code:
    [06:36:59] Loading script ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Characters/Bunny/BunnyLogic.as
    [06:36:59] Loading script ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Scripts/BF_Gooable.as
    [06:36:59] Loading script ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Scripts/BF_MaterialsFromTiles.as
    [06:36:59] Loading script ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Scripts/BF_FallSounds.as
    [06:36:59] Loading script ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Scripts/BF_RunnerDeath.as
    [06:36:59] Loading script ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Scripts/BF_LappelDuVide.as
    [06:36:59] New blob: netid 75 cacheindex 24 name bf_bunny config bf_bunny
    [06:36:59] <RCON> Koda (FunATuns) has joined Bunnies
    [06:36:59] New blob: netid 78 cacheindex 119 name mat_wood config mat_wood
    [06:37:02] <RCON> CRules Command GameplayEvent not found; add it first in onInit()
    [06:37:02] Loading script ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Buildings/Scripts/BF_DefaultBuilding.as
    [06:37:02] Loading script ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Buildings/Workshop/BF_Workshop.as
    [06:37:03] Loading script ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Scripts/BF_BioblockOnHit.as
    [06:37:03] New blob: netid 79 cacheindex 23 name bf_workshop config bf_workshop
    [06:37:03] Files have the same name! (rename for safety) ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Buildings/Workshop/BF_WorkshopIcons.png - ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Buildings/Hall/BF_WorkshopIcons.png
    [06:37:03] Files have the same name! (rename for safety) ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Buildings/Hall/BF_WorkshopIcons.png - ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Buildings/Workshop/BF_WorkshopIcons.png
    *Built here
    [06:37:03] Loaded texture: C:/Program Files (x86)/Steam/SteamApps/common/King Arthur's Gold/Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Buildings/Roast/BF_Roast.png
    [06:37:18] hits count mismatch in blob fishy (left 1) - is an onHit() function only on server?
    
    [06:37:20] hits count mismatch in blob fishy (left 1) - is an onHit() function only on server?
    
    [06:37:20] Loading script ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Natural/Flora/Carrot/BF_CarrotPlant.as
    [06:37:20] New blob: netid 86 cacheindex 56 name bf_carrotplant config bf_carrotplant
    [06:37:20] New blob: netid 85 cacheindex 56 name bf_carrotplant config bf_carrotplant
    [06:37:20] New blob: netid 84 cacheindex 56 name bf_carrotplant config bf_carrotplant
    [06:37:20] New blob: netid 83 cacheindex 56 name bf_carrotplant config bf_carrotplant
    [06:37:20] New blob: netid 82 cacheindex 56 name bf_carrotplant config bf_carrotplant
    [06:37:20] New blob: netid 81 cacheindex 56 name bf_carrotplant config bf_carrotplant
    [06:37:21] hits count mismatch in blob fishy (left 1) - is an onHit() function only on server?
    
    [06:37:42] Resizing window (1024 768)
    [06:37:50] DISCONNECTED FROM SERVER
    [06:37:50] *Restarting Map*
     
    Last edited: May 6, 2015
  6. Skinney

    Skinney THD Team THD Team Forum Moderator Tester

    Messages:
    468
    Can you include your console log?
     
  7. FunATuns

    FunATuns Builder Carry Donator

    Messages:
    114
    Last edited: May 6, 2015
  8. Fernegulus

    Fernegulus Bison Rider

    Messages:
    400
    That's not the entire log, is it?
     
  9. Skinney

    Skinney THD Team THD Team Forum Moderator Tester

    Messages:
    468
    Can you upload your servers console log in it's entirety? I've included how to do so in steps below.
    1. Launch your server
    2. Close your server
    3. Upload your King Arthurs Gold\Logs\console-most-recent-date.txt
     
  10. FunATuns

    FunATuns Builder Carry Donator

    Messages:
    114
    Ok
    My server is up right now. @Skinney
     

    Attached Files:

  11. Skinney

    Skinney THD Team THD Team Forum Moderator Tester

    Messages:
    468
    Found your error, based off this information try to figure out what's wrong. If you still can't figure it out click the spoiler.

    Code:
    [06:36:40] Loading script ../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Buildings/Roast/BF_Roast.as
    [06:36:40] Script: Compiling void onCommand(CBlob@, uint8, CBitStream@)
    [06:36:40] Script: Expected '('
    [06:36:40]         [line 60 char 5]     if else (cmd == "Roast" && this.get_bool( "Roaston"))
    [06:36:40]         in file '../Mods/Bunnyfection/Mods/BunnyFection_v1.3/Entities/Buildings/Roast/BF_Roast.as':
    http://www.learncpp.com/cpp-tutorial/52-if-statements/
    Change 'if else' to 'else if'
     
  12. FunATuns

    FunATuns Builder Carry Donator

    Messages:
    114
    oooohhhhhh oh my gosh, I feel so dumb. Thank you very much for taking the time to fix my dumb mistake. Thank you very much. Skinney. Have a great day.
     
  13. Skinney

    Skinney THD Team THD Team Forum Moderator Tester

    Messages:
    468
    No problem, solved and closed.
     
Thread Status:
Not open for further replies.