A cool game I made


#21

Yes, I have played Cookie Clicker, and I looked at the CSS.

The code seemed messy and… weird. And it seemed it just didn’t want to exist, or didn’t understand why it was like that. I could tell this by looking at the comments /* */.

I don’t even know why…


#22

Oh, thanks for putting it on repl.it, @mtf! Could you at least give me some credit though? I did this after a couple of days, so, that’s why I’m asking.


#23

I think this is the case in lots of programs and games. This game is made by a student in the early 2000’s i think. Became pretty popular for a while till people figured out it’s just a waste of time playing it XD


#24

Yes. A lot of games may contain messy code. Sometimes you can’t change it however. For this you can and with other games. Many older games are the messier ones usually. Newer games usually have more readable code.

I hope this helps =)


#25

I did. There is a link back to the top of this topic in the heading.

Yes, I got it working without much fuss, apart from a couple of small tweaks and the one big question regarding the different logic in the last five cases and the lack of if..else if...else if...else.


#26

You know what && means, right? It means and.

So my only solution to put logic here was to use these, in such a primitive way. I had no other choice, but to just use it like that.

Keep in mind, I had learnt this from the site, so I wasn’t too sure how to make simplistic use of it.


#27

Oops… well I made a part in that novel by accident.

I forgot the other ), and I didn’t even notice…


#28

Check the latest repl. The earlier ones should be in the history.

Most significantly,

if (points >= N && ! achievementsN)

We don’t need the OR.


#29

Oh I forgot, && actually meant OR! Oops! Sorry about that!


#30

No, you were right the first time.

 !  =>  NOT
&&  =>  AND
||  =>  OR

These operators have precedence. The above illustrates the order of operation. NOT after brackets, then AND, and finally OR.

if (A || B && ! C)

will evaluate ! C first so it will be a negated boolean.

Next, B && ! C are evaluated. If ! C is false, then this expression will be false regardless what B is. Finally we get to OR, and if A is true the expression will yield true regardless what the rest does. If false then the rest of the expression has to be true for the final yield to be true.

if ( (points == 10000000000 || points > 10000000000) && !gotAcheivement10 == false)

Your pattern above is,

if ((A || B) && ! C)

So it gets evaluated with brackets coming first.

aORb = A || B

and becomes,

if (aORb && ! C)

which now just has two steps to completion. Negate C and AND it with aORb. The yield is true only if both operands are true.

The question that came up in my mind is the necessity for all that in the first place. That’s why I simplified the line to just,

if (points >= 1E10 && ! gotAchievement10)

I used Scientific Notation to reduce possible errors with the huge numbers. Looking into the future, this line will lend itself to a dynamic handler that will elliminate all the if statements in that function. You’d be amazed how much we can still pare this code down.

That’s not the concern, just now. That you are getting a handle on logical operators and their expressions is all that really matters, for now. Once you have a good chunk of the language under your belt, your own mindset will drift in this direction, or your teacher will nudge you to take on a dynamic mindset rather than spaghetti code. There is nothing wrong with your code, so long as all the logic is correct.

You will have observed how different points of view arise and this gives us lots of playing room to sample various techniques. You should sample as many as you can get your hands on or dream up and dissect them to the minutest detail as you learn and review.

Nobody is expecting you to write your code like me. Take the good bits and leave what you don’t understand in favor of what you know already works. If you periodically come back around to old projects then that is perfect fodder for trying new things where the expectations are known, and clear. Be sure to save each revision so you can walk back if something goes wrong.


#31

Wow, I suppose that was simplified very nicely!

Roy, I will try to follow your advice the next time I make something like this. Thanks :slight_smile:


#32

So what kind of code would this be, according to you?

  • Primitive code
  • Repetitive code
  • Unorganized code
  • Neat code

0 voters


#33

Nice job on getting trust level 2 @_markviii.

That game is pretty cool :sunglasses:


#34

Thanks, @icetomeetyou!

I would appreciate you viewing the code, and voting on the poll above your post :slight_smile:


#35

Ok! I will to help you out @_markviii! Ok…I answered!


#36

Thanks, I appreciate the feedback :smile:


#37

That’s completely backwards :confused:
A first, then possibly B, and then possibly C

function a() {
    console.log('A')
    return false
}
function b() {
    console.log('B')
    return true
}
function c() {
    console.log('C')
    return true
}


a() || b() && ! c()

output:

A
B
C

#38

Okay, now another poll.

How do you think the expression a || b && ! c gets evaluated by JavaScript?

  • b, c, then a
  • a, b, then c
  • b, a, then c

0 voters


#39

(my post contains proof, just saying)


#40

Well, why not vote in the poll if you believe it’s evaluated that way? :slight_smile: