Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Please read the forum rules before posting.



Check if you are posting in the correct category.



The Off Topic section is not meant for discussing Cookie Clicker.
⚠️ The DashNet forums will be shut down on September 12th 2019.⚠️

Please see here for more information.

A bit of help with coding

lgpihllgpihl Posts: 73Member ✭✭
Hello!
I'm new on the forums (first post woo!), and I'm currently trying to code a mod of sorts, starting with adding a new building. It's called a Cloner. The problem is, I insert the code, and an error pops up saying ''undefined' is not an object (evaluating 'this.canvas.clientWidth')'. ALSO: Playing on beta, hope that doesn't effect anything. There is actually much more to the code I have currently (also adding new achievements and upgrades), but I just need help with the actual building part right now. Here's the code:
new Game.Object('Cloner', 'cloner|cloners|cloned', 'A cloner to clone your cookies.', 'clonerIcon', 15, {
base: 'cloner',
xV: 32,
yV: 32,
w: 64,
rows: 1,
x: 0,
y: 0
}, 4000000000000000000);
Thanks in advance!

Logan
I LIVE I DIE I LIVE AGAIN

(im baaaaack)
Tagged:

Comments

  • FatChicken18FatChicken18 Posts: 1,172Member ✭✭✭
    I don't know much about coding, but welcome to the forums!
    There's no braining involved - Gouchnox
    Please reads the OP - Gardevoir
  • lgpihllgpihl Posts: 73Member ✭✭

    I don't know much about coding, but welcome to the forums!

    Why tank chu!
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
  • lgpihllgpihl Posts: 73Member ✭✭
    (buhmp)
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
  • lgpihllgpihl Posts: 73Member ✭✭
    No one? Please, I'd really love some help.
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
  • ShylightShylight Posts: 6,436Moderator, Friendly, Helpful, Flagger Mod
    IIRC you need to create a button for a building first.

    Also no need to bump stuff so often — forum is a rather slow-paced way of talking, but it eventually gets there.
    SparklebuttimagePurplesmart
  • lgpihllgpihl Posts: 73Member ✭✭
    Ah, thank you! How would I go about creating one? Also, won't happen again with the over-bumping. :)
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
  • ShylightShylight Posts: 6,436Moderator, Friendly, Helpful, Flagger Mod
    I honestly don't remember. It's quite possible it'll be either in this thread or in one of @Zyzzyzus‌'.
    SparklebuttimagePurplesmart
  • [Deleted User][Deleted User] Posts: 4,188
    edited September 2014
    The user and all related content has been deleted.
    I had a dream my life would be
    So different from this hell I'm living
    So different now, from what it seemed
    Now life has killed the dream I dreamed
  • lgpihllgpihl Posts: 73Member ✭✭
    Thanks! I understand zero percent of all that o.o

    I will use those threads, thank you both! (jeez that wall of code though)
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
  • lgpihllgpihl Posts: 73Member ✭✭
    edited September 2014
    Oh yay, looky me nooby coder needing even MORE help! :D

    So, I'm coding a bit thanks to Zyzzyzus and Shylight, and I paste this into the console (huge wall of code inside):
    function initialize() {
    overrideRebuildStore();
    addCloner();



    }


    function addCloner() {

    //BUILDING
    var b = new Game.Object("Cloner","cloner|cloners|cloned","A cloner to clone your cookies.","cloner","clonerIcon","clonerBackground",4000000000000000000,function(){
    var add=0;
    return Game.ComputeCps(40000000000000000,Game.Has('Cloned grandmas') ? (Game.Objects['Grandma'].amount * 0.01 : 0) + Game.Has('Complex computations') + Game.Has('Enhanced machinery') + Game.Has('Molecular recreation') + Game.Has('Stabilization') + Game.Has('Precision clicking') + Game.Has('DNA reformation'),add)
    },Game.NewDrawFunction(0,16,16,64,2,32),function(){
    //Upgrades
    if (this.amount>=1) Game.Unlock(['Complex computations','Enhanced machinery']);
    if (this.amount>=10) Game.Unlock('Molecular recreation');
    if (this.amount>=50) Game.Unlock('Stabilization');
    if (this.amount>=100) Game.Unlock('DNA reformation');
    if (this.amount>=Game.SpecialGrandmaUnlock && Game.Objects['Grandma'].amount>0) Game.Unlock('Cloned grandmas');

    //Achievements
    if (this.amount>=1) Game.Win('Creation quest');
    if (this.amount>=50) Game.Win('Cookie Cloner');
    if (this.amount>=100) Game.Win('Not its true form');
    if (this.amount>=150) Game.Win('It was made this way');
    if (this.amount>=200) Game.Win('Orteil would be proud');
    });
    //UPGRADES
    var u = [];
    order=450;
    u.push(new Game.Upgrade('Complex computations','Cloners are twice as efficient.The cookies used to taste insanely bland.',200000,[3,0]));
    u.push(new Game.Upgrade('Enhanced machinery','Cloners are twice as efficient.The machine\'s twice as quick now!',2000000,[3,0]));
    u.push(new Game.Upgrade('Molecular recreation','Cloners are twice as efficient.Before this it barely looked like a cookie.',20000000,[3,1]));
    u.push(new Game.Upgrade('Stabilization','Cloners are twice as efficient.It... didn\'t explode?',100000000,[3,0]));
    u.push(new Game.Upgrade('Precision clicking','Cloners are twice as efficient.It used to miss the cookie 95% of the time.',1000000000,[3,0]));
    u.push(new Game.Upgrade('DNA reformation','Cloners are twice as efficient.A whole new cookie, never heard of before!',20000000000,[3,1]));
    for (var i=0;i1 cloner.',[4,0]));
    a.push(new Game.Achievement('Cookie Cloner','Have 50 cloners.',[4,1]));
    a.push(new Game.Achievement('It was made this way','Have 100 cloners.They\'re on the right track baby they were made this way',[4,2]));
    a.push(new Game.Achievement('Not its true form','Have 150 cloners.This isn\'t even my final form!',[4,13]));
    a.push(new Game.Achievement('Orteil would be proud','Have 200 cloners.How could you even afford that?',[4,14]));
    a[3].hide=2;
    for (var i=0;i0) list.push(choose([\n\
    'News : crazed man tries to clone himself, results in cookie monstrosity!',\n\
    'News : bland is the new tasty!',\n\
    'Breaking News! : another species of cookie was found during DNA reformation!',\n\
    'News : Orteil clones himself, results in millions of delicious games.'\n\
    ]));");


    //IMAGES

    changeIcon(b,"")
    changeBuildingLocation(b,4);
    Game.RebuildStore();
    changeDrawImage(b,"");
    changeBackground(b,""); //




    }


    And I get a 'SyntaxError: Expected token ')''.

    Anyone got a fix for this? Thanks in advance!

    ~Logan
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
  • lgpihllgpihl Posts: 73Member ✭✭
    BTW sorry for double post, but let me know if you want to see visual progress in-game so far! I have achievements and upgrades done already (both are useless except for the achs which give extra CpS if you have Kitten upgrades).
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
  • erdbeereerdbeere Posts: 3,384Member, Helpful ✭✭✭✭✭
    There is a ")" missing in your news section.
  • lgpihllgpihl Posts: 73Member ✭✭
    edited September 2014
    Really? Thank you! Will fix :p

    Can you point out exactly where?
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
  • lgpihllgpihl Posts: 73Member ✭✭
    Nevermind, found out. Pasted in, but still same error! What is WRONG with this code :(
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
  • ShylightShylight Posts: 6,436Moderator, Friendly, Helpful, Flagger Mod
    well, first of all I don't see overrideRebuildStore anywhere. Since you're calling it, it needs to exist. Your error simply tells you that you have more ( than ). Now, checking that can be a pain. I'd suggest getting an IDE. It will also help with any other error you might encounter.

    Anyway, here you have parenthesis missing in line 15 right before the colon: (Game.Objects['Grandma'].amount * 0.01 : 0
    SparklebuttimagePurplesmart
  • lgpihllgpihl Posts: 73Member ✭✭
    I should really post the entire code. Also, Shylight, it seems something's gone wrong on your end - that parenthesis ender exists there. Anyways, here's the FULL code:
    function initialize() {
    overrideRebuildStore();
    addCloner();



    }


    function addCloner() {

    //BUILDING
    var b = new Game.Object("Cloner","cloner|cloners|cloned","A cloner to clone your cookies.","cloner","clonerIcon","clonerBackground",4000000000000000000,function(){
    var add=0;
    return Game.ComputeCps(40000000000000000,Game.Has('Cloned grandmas') ? (Game.Objects['Grandma'].amount * 0.01 : 0) + Game.Has('Complex computations') + Game.Has('Enhanced machinery') + Game.Has('Molecular recreation') + Game.Has('Stabilization') + Game.Has('Precision clicking') + Game.Has('DNA reformation'),add)
    },Game.NewDrawFunction(0,16,16,64,2,32),function(){
    //Upgrades
    if (this.amount>=1) Game.Unlock(['Complex computations','Enhanced machinery']);
    if (this.amount>=10) Game.Unlock('Molecular recreation');
    if (this.amount>=50) Game.Unlock('Stabilization');
    if (this.amount>=100) Game.Unlock('DNA reformation');
    if (this.amount>=Game.SpecialGrandmaUnlock && Game.Objects['Grandma'].amount>0) Game.Unlock('Cloned grandmas');

    //Achievements
    if (this.amount>=1) Game.Win('Creation quest');
    if (this.amount>=50) Game.Win('Cookie Cloner');
    if (this.amount>=100) Game.Win('Not its true form');
    if (this.amount>=150) Game.Win('It was made this way');
    if (this.amount>=200) Game.Win('Orteil would be proud');
    });
    //UPGRADES
    var u = [];
    order=450;
    u.push(new Game.Upgrade('Complex computations','Cloners are twice as efficient.The cookies used to taste insanely bland.',200000,[3,0]));
    u.push(new Game.Upgrade('Enhanced machinery','Cloners are twice as efficient.The machine\'s twice as quick now!',2000000,[3,0]));
    u.push(new Game.Upgrade('Molecular recreation','Cloners are twice as efficient.Before this it barely looked like a cookie.',20000000,[3,1]));
    u.push(new Game.Upgrade('Stabilization','Cloners are twice as efficient.It... didn\'t explode?',100000000,[3,0]));
    u.push(new Game.Upgrade('Precision clicking','Cloners are twice as efficient.It used to miss the cookie 95% of the time.',1000000000,[3,0]));
    u.push(new Game.Upgrade('DNA reformation','Cloners are twice as efficient.A whole new cookie, never heard of before!',20000000000,[3,1]));
    for (var i=0;i1 cloner.',[4,0]));
    a.push(new Game.Achievement('Cookie Cloner','Have 50 cloners.',[4,1]));
    a.push(new Game.Achievement('It was made this way','Have 100 cloners.They\'re on the right track baby they were made this way',[4,2]));
    a.push(new Game.Achievement('Not its true form','Have 150 cloners.This isn\'t even my final form!',[4,13]));
    a.push(new Game.Achievement('Orteil would be proud','Have 200 cloners.How could you even afford that?',[4,14]));
    a[3].hide=2;
    for (var i=0;i0) list.push(choose([\n\
    'News : crazed man tries to clone himself, results in cookie monstrosity!',\n\
    'News : bland is the new tasty!',\n\
    'Breaking News! : another species of cookie was found during DNA reformation!',\n\
    'News : Orteil clones himself, results in millions of delicious games.'\n\
    ])));");


    //IMAGES

    changeIcon(b,"link")
    changeBuildingLocation(b,4);
    Game.RebuildStore();
    changeDrawImage(b,"link");
    changeBackground(b,"link"); //link




    }

    function overrideRebuildStore() {
    (function() {
    var oldVersion = Game.RebuildStore;
    Game.RebuildStore = function() {
    var result = oldVersion.apply(this, arguments);
    for (var v in Game.Objects) {
    var a = Game.Objects[v];
    if (a.customIcon!=undefined) {
    $id("productIconOff"+a.id).style.backgroundImage="url("+a.customIcon+")";
    $id("productIcon"+a.id).style.backgroundImage="url("+a.customIcon+")";
    }
    }

    };
    })();
    }
    function changeIcon(building,iconURL) {
    building.customIcon=iconURL;
    }
    function changeDrawImage(building,imageURL) {
    (function() {
    var oldVersion = Game.NewDrawFunction(0,16,16,64,2,32);
    building.drawFunction = function() {
    var result = oldVersion.apply(this, arguments);
    var chil = ($id('rowObjects'+building.id)).children;
    for (var i =0;i
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
  • ShylightShylight Posts: 6,436Moderator, Friendly, Helpful, Flagger Mod
    It seems you misunderstood me. Or I wasn't good enough at explaining.

    image

    Just to explain. Here the ternary operator is used. To keep it short: it's a fancy way to write an If-then-else statement. It follows this pattern:

    condition ? true : false

    Can you see the problem yet? The "true" part in your code contains opening bracket, but no closing one, so it doesn't work. Removing the opening one will also work, since they were added for clarity n this case.
    SparklebuttimagePurplesmart
  • lgpihllgpihl Posts: 73Member ✭✭
    Oh ok. Thank you very much! Will respond again with results in a few hours.
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
  • lgpihllgpihl Posts: 73Member ✭✭
    edited September 2014
    So of course, another error. I put it like you said, and it comes back with Unexpected ). o.o
    Then I deleted the parenthesis after the 0 in the Cloned Grandmas achievement, and it came up with ANOTHER error! This time, it's NOT an 'unexpected' or 'expected' thingy. It comes up with:

    TypeError: 'undefined' is not a function (evaluating 'Game.NewDrawFunction(0,16,16,64,2,32)')
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
  • ShylightShylight Posts: 6,436Moderator, Friendly, Helpful, Flagger Mod
    Game.NewDrawFunction is not defined anywhere in the code. I don't really know how it worked for code's author.
    SparklebuttimagePurplesmart
  • lgpihllgpihl Posts: 73Member ✭✭
    Ha! So, what should I do now, seeing as how I have no idea how to code a Game.DrawNewFunction? Also, thanks for the response.
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
  • lgpihllgpihl Posts: 73Member ✭✭
    *bump*
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
  • ShylightShylight Posts: 6,436Moderator, Friendly, Helpful, Flagger Mod
    I have no idea, to be honest. You could simply google "how to add an element to the page with javascript", look at any other button in the store and simply construct your own. It might even work.
    SparklebuttimagePurplesmart
  • lgpihllgpihl Posts: 73Member ✭✭
    edited September 2014
    I think I'd rather remove it, since it doesn't seem to do anything in retrospect. So, I pasted it in with the removed Game.DrawNewFunction. It gave an Unexpected ). And I gave up. xD *ragequit* If you still want to help, much obliged.
    I LIVE I DIE I LIVE AGAIN

    (im baaaaack)
Sign In or Register to comment.