New games every week!
JSE - Variables Blog
30th April 2021
Right then, time to tackle variables.. Aaargh!!!

-=-=-

I sat, staring at the code.
I had a vague plan in mind.
Making use of Javascript's internal "Strings as keys in an array" functionality, this shouldn't be too hard of a task.

I headed to the Keywords area, and added an internal "Let" command.

The plan isn't to make you write the word Let, but instead to have it automagically pop a Let into the script, wherever a Let is needed.
The Let command is merely a "suggestion" to the script engine, and is placed in front of any variables that are themselves in front of a single equals sign.

So, I added that, and then added a rather simple "If this isn't a keyword, assume it's more than likely a variable" thing at the end of the script.
I added setting and reading of the variable, made use of the Let to tell it when it should be setting or reading, and the functionality that was already in for "n" numbers was used to plonk the values back into memory..
and ..
then..
um..

Yeah, that works.

// Shape Chase // by Jayenkai // Created 2021/4/28 Graphics 512,512,1 Repeat CLS 0,120,0,0.1 // Hexagon moves around HexX=Sin(Mills()/5)*240 HexY=Cos(Mills()/7)*240 // Tri follows Hex TriX=TriX-((TriX-HexX)/16) TriY=TriY-((TriY-HexY)/16) // Oct follows the Mouse OctX=OctX-((OctX-MouseX())/16) OctY=OctY-((OctY-MouseY())/16) InkRot 30,1,1 Oval TriX+256,TriY+256,32,32,3 InkRot 190,1,1 Oval HexX+256,HexY+256,32,32,6 size=32*(MouseDown()+1) InkRot 280,1,1 Oval OctX,OctY,size,size,8 Flip Forever


You can try out the above script, in JSE, here.

Within just a couple of hours, I had Variables working as expected, and I was quite surprised that they worked as well as they do. (*hopefully!!)

I also added simple Mouse control, too, because.. Why not!?!
It's all coming together much easier than I intended. Which is usually the point at which things break in ways I could never have foreseen!!

The next step is either to tackle Arrays or For/Next loops. Or maybe If's...
Not sure which.
Who knows!!
Views 193, Upvotes 10  
Daily Blog , Jse
New games every week!
Site credits : Jayenkai
(c) Jayenkai 2023 and onwards, RSS feed

Blog - JSE - Variables - AGameAWeek