Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Making a shop for a idle clicker game

New Here ,
Mar 02, 2017 Mar 02, 2017

Hi, I am trying to make a cookie clicker type of game, I have sorted out on how to get the score going but I cannot make a shop.

My ideas on how to script this are if(the score == 5) then unlock the shop and -5 cookies that I spent to buy the item.

var numberOfCookies:Number=0

circle.addEventListener(MouseEvent.CLICK,plus)

function plus(e:MouseEvent){

  score.text=new String(numberOfCookies)

  numberOfCookies+=1

}

function init():void

{

    if (numberOfCookies >= 5)

  {

  numberOfCookies-=5

  }

}

this is my try at the moment I have been testing different ways I may be able to do this and I cannot figure it out.

671
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 02, 2017 Mar 02, 2017

1. There is no reason for the init() function. You can add the event listener to box without that function.

2. You have a function called shop, you don't need this at all.

3. You can combine updateScore() with plus(). Something like this:

var numberOfCookies: Number = 0

circle.addEventListener(MouseEvent.CLICK, plus);

  function plus(e: MouseEvent):void {

     // increment the value in numberOfCookies

       numberOfCookies += 1

     // if the value is equal to 5 then subtract 5 from the value

      if (

...
Translate
LEGEND ,
Mar 02, 2017 Mar 02, 2017

I'm not really sure what you're attempting to do, but... If you want to change the number of cookies that shows in the score at each click on the circle button, then update the text at the end of the function, not at the start. Everything in Actionscript happens in the order that you write in your function, so now you are setting the score value, then updating the number in the numberOfCookies variable. You actually want the opposite.

So, to get what I think that you want you might change the function to something like this:

function plus(e:MouseEvent){

  numberOfCookies+=1

    if (numberOfCookies >= 5)

  {

  numberOfCookies = 5;

// this is where you should add in the action to open the store

// I'm guessing that you also want to change the numberOfCookies to 0 either here, or after the open the store thing happens

  }

  score.text=new String(numberOfCookies)

}

Is that anything like what you had in mind?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 02, 2017 Mar 02, 2017

Okay, I worked out what I wanted to do, sorry if I made it a bit confusing there are many parts to this. Now the only problem is that when the cookies get -5 from the total score it does not change the score instantly, it only updates when I add +1 again.

var numberOfCookies: Number = 0

circle.addEventListener(MouseEvent.CLICK, plus)

  function plus(e: MouseEvent) {

  score.text = new String(numberOfCookies)

  numberOfCookies += 1

  }

  function init(): void {

  box.addEventListener(MouseEvent.CLICK, shop)

  }

  function shop(event: MouseEvent): void {

  updateScore();

  }

  function updateScore(): void {

  if (numberOfCookies >= 5) {

  numberOfCookies -= 5

  }

  }

  init();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2017 Mar 02, 2017

1. There is no reason for the init() function. You can add the event listener to box without that function.

2. You have a function called shop, you don't need this at all.

3. You can combine updateScore() with plus(). Something like this:

var numberOfCookies: Number = 0

circle.addEventListener(MouseEvent.CLICK, plus);

  function plus(e: MouseEvent):void {

     // increment the value in numberOfCookies

       numberOfCookies += 1

     // if the value is equal to 5 then subtract 5 from the value

      if (numberOfCookies == 5) {

            numberOfCookies -= 5

       }

     // update the text in score

       score.text = new String(numberOfCookies)

  }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2017 Mar 03, 2017

Thank you what I was missing is the update for the text score, that is why I did not see the number change as soon as I pressed it. Although I do need the other event handler because I want it to -5 when I pressed another button not just when i reach 5 points. I have that all figure out thanks for the help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2017 Mar 03, 2017
LATEST

You're welcome, good luck with the rest of your project.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines