I need some help with the coding of a game I am working on

Started by
10 comments, last by armen8 3 years, 3 months ago

Well, you see here I need help with getting this

<upgrade1>
   <button type="button" class="button button1">
     <a>Money Upgrade:</a>
     <a id="money">1</a>
     <p>Cost: $<a id="money cost">2.00</a></p>
   </button>
</upgrade1>

to appear when you get to $2.00 and stay appeared. Also, I want the amount of money you have not to go below $0.00 and I want help with some other things as well. So here is the rest of the code you will need to help me:

HTML:

<body>
    <p>Money: $<a id="clicks">0.00</a></p>
    <hr>
    <img src="Money.png" alt="Increase Money" title="Click Me to increase the Money." type="button" onclick="moneyOne()" class="clicked">
    <hr>
    <upgrade1>
      <button type="button" class="button button1">
        <a>Money Upgrade:</a>
        <a id="money">1</a>
        <p>Cost: $<a id="money cost">2.00</a></p>
      </button>
    </upgrade1>
    <script src="script.js"></script>
  </body>

Javascript:

var clicks = 0.00;
var money = 1
var moneycost = 2.00
var timer;
var img = document.querySelector(".clicked");

function moneyOne() {
  clicks += 0.01;
  document.getElementById("clicks").innerHTML = clicks.toFixed(2);
  img.classList.add("active");
  if (timer) window.clearTimeout(timer);
  timer = window.setTimeout(function() {
    img.classList.remove("active");
  }, 200);
};

function moneyUpgrades() {
  if (clicks = 2.00) 
  document.getElementById("money").innerHTML = money;
  document.getElementById("moneycost").innerHTML = moneycost;
  money += 1;
  moneycost += 2.00
  clicks -= 2.00
};

CSS:

.clicked {
  width: 410px;
  height: 200px;
  transition: all .2s ease-in-out;
  transform: scale(1);
}

.clicked.active {
  transform: scale(.6);
}

.button {
  position: absolute;
  z-index: 1;
  border: none;
  color: white;
  padding: 16px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  transition-duration: 0.4s;
  cursor: pointer;
}

.button1 {
  background-color: white;
  color: black;
  border: 2px solid #008CBA;
}

.button1:hover {
  background-color: #008CBA;
  color: white;
}

upgrade1 {
  display: none;
}

Also, if you see anything wrong or not necessary with my coding please tell me.

– Erik P. Kountzman - Owner - of - Airent Animation Entertainment --

Advertisement

fleabay said:

“I don't know javascript, will you help me fix my feeble attempts at cobbling together code that I don't really understand?”

I don't really know Javascript, as well, but I know how to piece together the lines of code in the script if I have found the code. Also, I do sort of understand Javascript, not very well, but I understand it enough to use it. Also, do you even know how to code, if you do what types of code can you do (like python, HTML, CSS, Javascript, etc.)?

– Erik P. Kountzman - Owner - of - Airent Animation Entertainment --

script kiddie

noun

informal•derogatory

noun: script kiddie; plural noun: script kiddies; noun: script kiddy

a person who uses existing computer scripts or codes to hack into computers, lacking the expertise to write their own.

Sorry dude but do your homework first! Then come back with specific questions you need help with >after< you tried to find a solution on your own.

If you want something to appear in HTML by script, get a reference and either set the display property or give it a class that has the proper settings set.

To determine if something is equal or greater, the gequal-operator helps and this works as well for the other part of your condition to not get below zero

-lol- “i don't really know how to drive a car but just let me drive it”

… to appear when you get to $2.00 and stay appeared.

hmm, okay, to keep UI elements on the screen, this is usually done in 2 ways:

  • retained [GUI] mode (usually abbreviated as RTM)
  • immediate [GUI] mode (usually abbreviated as IMGUI)

… but I know how to piece together the lines of code in the script if I have found the code.

right, so then have a look at this code: https://gist.github.com/gkhays/e264009c0832c73d5345847e673a64ab

I know it's a bit much, but see how the wave stays onscreen, pay attention to the init( ) function and the requestAnimationFrame( parameter ) , see how they are used. If you can do it this way then you are going to be keeping your UI onscreen the IMGUI way (using javascript). You will then be able to control when to show your UI when money is greater or equal to $2.00 and keep it onscreen on the next frame.

You can also use setTimeout( ) and refresh( ) if i remember well to refresh your screen in the same IMGUI fashion.

Hope this helps.

That's it … all the best ?

Officer_Erik_K said:
Also, if you see anything wrong or not necessary with my coding please tell me.

XML

  • What is the intent with this bit? Is that something you want to convert from, into markup?

HTML

  • image with title="Click Me to increase the Money." type="button" attributes
  • I don't know what you're targeting, but upgrade1 might not be a valid tag
  • what are you using the a-tags for? The current usage is that they are link placeholders. Why would you want that?

Javascript (Oh boy…)

  • You're comparing floating point values. This is normally a big no, but JS might accommodate somehow. Still looks odd though.
  • You're using a combination of ; and non-; line endings
  • What is moneyUpgrades, and why is it here at all?

CSS

  • .clicked
    • Why would you transition every property?
    • Why would you scale(1)
  • .clicked.active
    • Please look into :active as well as css animations and proper usage of the transition property
  • .button
    • Why are you specifying position, z-index, text-align, text-decoration, display and cursor
    • Why are you setting transition-duration here? Wouldn't it be nicer if it went with the other transition rule?
    • Why would you like white for the color here, and white for the .button1 background-color?

That was just the technical parts of the feedback. The way your example is written out, namely the Javascript, makes it very clear that you have no experience with software development. That's ok - we all have to start somewhere, but please make sure to get some practice before asking people here to help with your work, or ask questions related to learn a specific thing.

This is just a matter of knowing how to program: Counting clicks and altering floating point values for the intended purpose is just very bad practice, but how you've composed that various events, the class names you use and the attributes you've used is a lot of effort to very little result, while convoluting the code unnecesarily. It's not that your solution isn't right, but it's hardly even wrong.

Did you look into twine yet - otherwise there are lots of good resources on web technologies out there. I can recommend MDN for lots of good examples.

Officer_Erik_K said:

…do you even know how to code

He's onto you, @fleabay !

E: comment on <a> usage.

SuperVGA said:

XML

  • What is the intent with this bit? Is that something you want to convert from, into markup?

There is no XML in my code. (I believe.) Nor am I going to use XML.

SuperVGA said:

HTML

  • image with title="Click Me to increase the Money." type="button" attributes
  • I don't know what you're targeting, but upgrade1 might not be a valid tag

Well, there are no errors with the upgrade1 tag, it does work, so it is useable.

SuperVGA said:

Javascript (Oh boy…)

  • You're comparing floating point values. This is normally a big no, but JS might accommodate somehow. Still looks odd though.
  • You're using a combination of ; and non-; line endings
  • What is moneyUpgrades, and why is it here at all?

Well, the code is not finished yet, and the moneyUpgrades is apart of the money upgrade, witch the money upgrade increases the amount of money you get per click of the money image.

SuperVGA said:

CSS

  • .clicked
    • Why would you transition every property?
    • Why would you scale(1)
  • .clicked.active
    • Please look into :active as well as css animations and proper usage of the transition property
  • .button
    • Why are you specifying position, z-index, text-align, text-decoration, display and cursor
    • Why are you setting transition-duration here? Wouldn't it be nicer if it went with the other transition rule?
    • Why would you like white for the color here, and white for the .button1 background-color?

I don't know how to answer these questions about the CSS of my code.

SuperVGA said:

Did you look into twine yet - otherwise there are lots of good resources on web technologies out there. I can recommend MDN for lots of good examples.

Yes, I have looked at twine, but I haven't used it yet.

– Erik P. Kountzman - Owner - of - Airent Animation Entertainment --

@officer_erik_k I think it's a bit strange that you ask for help and then dismiss the help like you did above.
How do you plan on writing the rest of the game, let alone the condition to not have the money go below zero, if you don't right the issues with your existing code?

@officer_erik_k Let me worry about Money LIfe Clicker, since you are not the one working on it, I am working on it, after all, you have Mystical Sanctum Ruins to worry about.

– Cardeon Denmen - Head of Advertisement - at - Airent Animation Entertainment --

SuperVGA said:

@officer_erik_k I think it's a bit strange that you ask for help and then dismiss the help like you did above.
How do you plan on writing the rest of the game, let alone the condition to not have the money go below zero, if you don't right the issues with your existing code?

Hi, he doesn't know what he is doing, since he isn't supposed to working on this project, he is supposed to be working on Mystical Sanctum Ruins. Also, my code is a lot better than his after all I know how to do all of the needed things, but I am using two different code methides, one is that I will use Scratch to make the clicker game part and then ether use HTML, CSS, and Javascript or use Python. Which one would you suggest to me to use? If you think something else might work better don't be afraid to tell me.

– Cardeon Denmen - Head of Advertisement - at - Airent Animation Entertainment --

This topic is closed to new replies.

Advertisement