| A_of-s_t | Mar 24 2008, 4:02 am | Post #1 |
|
Master of Temptation, Ruler of Aeronotics, and Secret Lover
|
Tips for Tedious Coding
Part 1 -- Tips for Tedious Coding: An Introduction into Javascript Have you ever had to produce tedious lines of code, or wanted to produce a cool effect, but didn't feel like writing everything out? Now, I shall unveil and easy way for the production of tedious lines of code. Yay! Have you ever heard of javascript? Its a type of scripting language -- but heres the secret -- that is uncompiled. All you need is a text editor! So, lets open up our favorite text editor -- which I shall assume is Notepad++. Introduction: Now, let's type in the basic part of the script that we need: Codevar fso = new ActiveXObject("Scripting.FileSystemObject"); var outputFileName = fso.GetParentFolderName(WScript.ScriptFullName) + "\\" + fso.GetBaseName(WScript.ScriptFullName) + ".txt"; var outputStream = fso.CreateTextFile(outputFileName, true);" -Line 1 states we are creating a new object. -Line 2 states what its name shall be. -I don't really know what Line 3 is (I'm guessing it is merely outputs untill told to stop.) Now, lets make something we can all enjoy: SPINNING PROBES!!!!! Codevar currentSpinSpeed = 1; while(currentSpinSpeed < 13) { currentSpinSpeed *= 1.02; outputStream.WriteLine(" turncwise " + Math.floor(currentSpinSpeed)); outputStream.WriteLine(" wait 1"); } So, we set our variable "currentSpinSpeed" equal to one. While this variable is less than 13, we multiply it by 1.02. In the text file it will output, it will write the line "turncwise + Math.floor(1.02)" -> "turncwise 1" Can you see with Math.floor does? It takes any non-interger and round it DOWN. Now, our code is almost done, all we need is one final line: CodeoutputStream.Close(); We tell our program to finish and close the file. Our final code looks like: Save the file as: probeBuildUp.js. Now click on the file and it will create probeBuildUp.txt. *This javascript originally comes from BSTRhino. I have used it because if its simplicity -- yet stunning visual effect I luve spinning probes ----------------------------------- Bouncing Grenades: I have always loved this effect, and all it requires is iscript magic. Codevar currentFrameNumber = 0; Set the current frame number. Codefunction generatePlayFrameCommand() { outputStream.WriteLine(" playfram " + currentFrameNumber); ++currentFrameNumber; if(currentFrameNumber >= 4) { currentFrameNumber = 0; } } We define a function that we will use later in the code. You probably can understand this except for a few things (if you are unfimiliar with coding santax). '++' == add one to the variable. '>=' == less than or equal to. Codevar arcStepArray = new Array(); for(var currentArcInitialStep = 1; currentArcInitialStep * 2 - 1 <= 64; currentArcInitialStep *= 2) { arcStepArray.push(currentArcInitialStep); outputStream.WriteLine("Arc" + arcStepArray.length + ":"); var currentHeightValue = 0; for(var currentStepValue = currentArcInitialStep; currentStepValue >= 1; currentStepValue /= 2) { currentHeightValue -= currentStepValue; outputStream.WriteLine(" shvertpos " + currentHeightValue); generatePlayFrameCommand(); outputStream.WriteLine(" wait 1"); } var currentDecrementValue = 1; while(true) { currentHeightValue += currentDecrementValue; if(currentHeightValue > 0) { break; } outputStream.WriteLine(" shvertpos " + currentHeightValue); generatePlayFrameCommand(); outputStream.WriteLine(" wait 1"); currentDecrementValue *= 2 } outputStream.WriteLine("goto Arc" + (arcStepArray.length - 1)); outputStream.WriteLine(); } outputStream.Close(); Now, for good practice, analyze that code and see if you can figure out what it means. Here are some tips: 'var1 += var2' == Variable #1 is equal to Variable #2 plus one. 'while(true)' == run this code while the output from is is a non-zero value. Here is the overall code needed for bouncing grenades: *Original script by BSTRhino. Why? Becuase he owns. ----------------------------------- Application of Javascript (and in fuller understanding -- coding in general) to Effects Using Mathematics: What I am going to create in this section is a circle of explosions that you can use as an attack or death animation for a unit. I usually use it for larger units' deaths and such. I know Starcraft incorporates a large array of players -- from youngling to expert elder -- so, skip this section if you understand polar equations. The equation for a circle using x and y's is Math.sqrt(x*x + y*y) = radius*radius. Writing that equation made me want to puke. Couldn't there be some easier way? Of course there is -- its called a polar equation. the equation for a circle is simply: r = 1. For a spiral, it is r = Theta. A Crash Course on Polor Equations: Polar equations relate angles with radii. At the given angle, the radius will be a certian length. At the end of the radius, it will plot the point. But how are those points found be people like you or me? By these set of equations: x = radius * cos(theta) y = radius * sin(theta) (This is basic Algebra and Trig. And some Geometry I guess... O well.) So, if we are going to use a polar equation in our javascript, we're going to need these two equations as functions: Code//functions function calcx(radians) { xasixnum = Math.round(Math.cos(radians) * 10); return xasixnum; } function calcy(radians) { yasixsum = Math.round(Math.sin(radians) * 10); return yasixsum; } Now, javascript uses radius, which differs from degrees. Degrees * pi / 180 = Radians We want our explosions to go full cicle so: Code// Program entry point for(var currentRadians = 0; currentRadians < 2 * Math.PI; currentRadians += Math.PI/16) { outputStream.WriteLine(" imgol 334" + " " + calcx(currentRadians) + " " + calcy(currentRadians)); outputStream.WriteLine(" playsndbtwn 7 12"); outputStream.WriteLine(" wait 1"); } outputStream.Close(); Here is our full code: *Original Code by A_of_s_t. It is currently being used in Disunion and my mod for the Summer Modding Contest. Please give me some kudos if you use these tips in your mod. Next up: Completely Random Atttack Sequences Next up: Application to Triggers Next up: Application to AI Design Nect up: Advanced Special Attacks and Spell with Application of |
||
|
This post was edited 9 times, last edit by A_of-s_t: Mar 25 2008, 4:56 am.
![]() From silent: "lolol First of all wikipedia is flawed because anyone can come into it and post anything. About criticism.. no. You can't just change the definition of a word and expect everyone to bow down in awe. I am using macro evolution as an identifier between changing from one kind to another kind. I.E. bananas turning into flies. So if you want to argue about this then your argueing about the definition of a word.. Not the theory itself. If you want I can use false evolution, or neverbeenseenbefore evolution instead of macro. Its up to you" This is stupidity. Please look at it very closely -- notice that almost every logical fallacy is used in it. |
| modmaster50 | Mar 24 2008, 4:25 am | Post #2 |
|
Why dont we just download UltiDoom and use the provided code generators?
Anyways, this should be added into a tutorial . Good work typing this all out!
|
||
| DT_Battlekruser | Mar 24 2008, 4:27 am | Post #3 |
|
I paid eleven minerals for THIS?
|
Javascript is such an ugly language considering you can do this in anything. I will grant you though that it is an interpreted language executed locally on any web browser.
|
||
| A_of-s_t | Mar 24 2008, 4:31 am | Post #4 |
|
Master of Temptation, Ruler of Aeronotics, and Secret Lover
|
Modmaster: Becuase it catches people's attention and it is very basic, that is why I used them. Duh.
It's a pretty straight forward language that I like becuase all you need is notepad to write it. The best part is that its syntax is similar to C++ and it can be used in web pages and such. EDIT: I'll add it to the tutorials after I'm completely finished. |
||
![]() From silent: "lolol First of all wikipedia is flawed because anyone can come into it and post anything. About criticism.. no. You can't just change the definition of a word and expect everyone to bow down in awe. I am using macro evolution as an identifier between changing from one kind to another kind. I.E. bananas turning into flies. So if you want to argue about this then your argueing about the definition of a word.. Not the theory itself. If you want I can use false evolution, or neverbeenseenbefore evolution instead of macro. Its up to you" This is stupidity. Please look at it very closely -- notice that almost every logical fallacy is used in it. |
| A_of-s_t | Mar 24 2008, 4:47 am | Post #6 |
|
Master of Temptation, Ruler of Aeronotics, and Secret Lover
|
It's a pretty straight forward language that I like becuase all you need is notepad to write it. The best part is that its syntax is similar to C++ and it can be used in web pages and such. EDIT: I'll add it to the tutorials after I'm completely finished. You only need notepad to write anything, But with javascript, there is no need to compile. |
||
![]() From silent: "lolol First of all wikipedia is flawed because anyone can come into it and post anything. About criticism.. no. You can't just change the definition of a word and expect everyone to bow down in awe. I am using macro evolution as an identifier between changing from one kind to another kind. I.E. bananas turning into flies. So if you want to argue about this then your argueing about the definition of a word.. Not the theory itself. If you want I can use false evolution, or neverbeenseenbefore evolution instead of macro. Its up to you" This is stupidity. Please look at it very closely -- notice that almost every logical fallacy is used in it. |
| Corbo[MM] | Mar 24 2008, 4:49 am | Post #7 |
|
LOL! DTBK actually paid for this!
|
@Syphon: Yes, but you need Java runtime environments, php installed and some other requirements for most of the other programming languages.
You can use notepad to write anything but you'll need something more than notepad to actually use it. |
||
| A_of-s_t | Mar 24 2008, 4:51 am | Post #8 |
|
Master of Temptation, Ruler of Aeronotics, and Secret Lover
|
But I think this is besides the point. I used javascript mainly because I lub it (that and C++). |
||
![]() From silent: "lolol First of all wikipedia is flawed because anyone can come into it and post anything. About criticism.. no. You can't just change the definition of a word and expect everyone to bow down in awe. I am using macro evolution as an identifier between changing from one kind to another kind. I.E. bananas turning into flies. So if you want to argue about this then your argueing about the definition of a word.. Not the theory itself. If you want I can use false evolution, or neverbeenseenbefore evolution instead of macro. Its up to you" This is stupidity. Please look at it very closely -- notice that almost every logical fallacy is used in it. |
| Syphon[MM] | Mar 24 2008, 6:32 am | Post #9 |
|
You can use notepad to write anything but you'll need something more than notepad to actually use it. Same with Javascript... |
||
![]() |
| Deathman101 | Mar 24 2008, 10:01 am | Post #10 |
|
Major General
|
Kudos for writing this out, but just about anything here can be done with the language IceCC uses...and if not you can come very close. The "no compiling" is extremely tempting though.
OFC if I learn Javascript in SC I can say my modding career taught me something relatively useful. |
||
|
This post was edited 1 time, last edit by Deathman101: Mar 24 2008, 10:10 am.
|
| AntiSleep | Mar 24 2008, 11:27 am | Post #11 |
|
The amount of time it takes to find and install a dev environment for ANY language is piddling to the amount of time saved from tedious triggers. I tend to prefer perl when triggering.
|
||
![]() I do not respect your beliefs, and I implore you not to respect mine. To ask respect of beliefs held without evidence, is to burn the books of progress and hope. - The Village IconoClast |
| A_of-s_t | Mar 25 2008, 1:01 am | Post #12 |
|
Master of Temptation, Ruler of Aeronotics, and Secret Lover
|
Will add to first post.
Application of Javascript (and in fuller understanding -- coding in general) to Effects Using Mathematics: What I am going to create in this section is a circle of explosions that you can use as an attack or death animation for a unit. I usually use it for larger units' deaths and such. I know Starcraft incorporates a large array of players -- from youngling to expert elder -- so, skip this section if you understand polar equations. The equation for a circle using x and y's is Math.sqrt(x*x + y*y) = radius*radius. Writing that equation made me want to puke. Couldn't there be some easier way? Of course there is -- its called a polar equation. the equation for a circle is simply: r = 1. For a spiral, it is r = Theta. A Crash Course on Polor Equations: Polar equations relate angles with radii. At the given angle, the radius will be a certian length. At the end of the radius, it will plot the point. But how are those points found be people like you or me? By these set of equations: x = radius * cos(theta) y = radius * sin(theta) (This is basic Algebra and Trig. And some Geometry I guess... O well.) So, if we are going to use a polar equation in our javascript, we're going to need these two equations as functions: Code//functions function calcx(radians) { xasixnum = Math.round(Math.cos(radians) * 10); return xasixnum; } function calcy(radians) { yasixsum = Math.round(Math.sin(radians) * 10); return yasixsum; } Now, javascript uses radius, which differs from degrees. Degrees * pi / 180 = Radians We want our explosions to go full cicle so: Code// Program entry point for(var currentRadians = 0; currentRadians < 2 * Math.PI; currentRadians += Math.PI/16) { outputStream.WriteLine(" imgol 334" + " " + calcx(currentRadians) + " " + calcy(currentRadians)); outputStream.WriteLine(" playsndbtwn 7 12"); outputStream.WriteLine(" wait 1"); } outputStream.Close(); Here is our full code: var outputFileName = fso.GetParentFolderName(WScript.ScriptFullName) + "\\" + fso.GetBaseName(WScript.ScriptFullName) + ".icc"; var outputStream = fso.CreateTextFile(outputFileName, true); //functions function calcx(radians) { xasixnum = Math.round(Math.cos(radians) * 10); return xasixnum; } function calcy(radians) { yasixsum = Math.round(Math.sin(radians) * 10); return yasixsum; } // Program entry point for(var currentRadians = 0; currentRadians < 2 * Math.PI; currentRadians += Math.PI/16) { outputStream.WriteLine(" imgol 334" + " " + calcx(currentRadians) + " " + calcy(currentRadians)); outputStream.WriteLine(" playsndbtwn 7 12"); outputStream.WriteLine(" wait 1"); } outputStream.Close(); *Original Code by A_of_s_t. It is currently being used in Disunion and my mod for the Summer Modding Contest. Please give me some kudos if you use these tips in your mod. |
||
|
This post was edited 1 time, last edit by A_of-s_t: Mar 25 2008, 1:07 am.
![]() From silent: "lolol First of all wikipedia is flawed because anyone can come into it and post anything. About criticism.. no. You can't just change the definition of a word and expect everyone to bow down in awe. I am using macro evolution as an identifier between changing from one kind to another kind. I.E. bananas turning into flies. So if you want to argue about this then your argueing about the definition of a word.. Not the theory itself. If you want I can use false evolution, or neverbeenseenbefore evolution instead of macro. Its up to you" This is stupidity. Please look at it very closely -- notice that almost every logical fallacy is used in it. |
| Centreri | Mar 25 2008, 1:30 am | Post #13 |
|
Overwin Winboat
|
Huh. For some reason, I never thought of using a programming language to generate stuff. This'll make trigger-generation easier. PHP>Javascript, though.
|
||
![]() Boatianity: A philosophy developed by Jesus Christ involving winboats and failboats. Those with lots of win are winboats. Those with lots of fail are failboats. Those in the middle are boats. Lends itself to epicness, such as 'May the win be with you' and 'The fail is strong with this one'. I recently switched my MSN ID to Centreri@Live.com. ADD ME IF I CARE ABOUT YOU. July 18-on (for a bit more then a month, too lazy to look up exact date) I shall be on vacation in Russia. In other words, my access to SEN will be limited and I will probably be completely unable to participate in map night . However, don't feel sorry for me. While you're playing SC I'll be speaking to crazy Soviets, so I'm going to have a great time. KEKEKE. |
| A_of-s_t | Mar 25 2008, 1:33 am | Post #14 |
|
Master of Temptation, Ruler of Aeronotics, and Secret Lover
|
For the first part: I'm going to create an Application to Triggering soon. For the second part: I don't care about personal prefrences. I'm writing this for javascript so deal with it. |
||
![]() From silent: "lolol First of all wikipedia is flawed because anyone can come into it and post anything. About criticism.. no. You can't just change the definition of a word and expect everyone to bow down in awe. I am using macro evolution as an identifier between changing from one kind to another kind. I.E. bananas turning into flies. So if you want to argue about this then your argueing about the definition of a word.. Not the theory itself. If you want I can use false evolution, or neverbeenseenbefore evolution instead of macro. Its up to you" This is stupidity. Please look at it very closely -- notice that almost every logical fallacy is used in it. |
| A_of-s_t | Mar 25 2008, 4:39 am | Post #15 |
|
Master of Temptation, Ruler of Aeronotics, and Secret Lover
|
Cannot add to 1st post at the moment so:
PART 2 -- Applications of Javascript (and to a more reaching extent -- coding in general) for Unique Weaponry The Miraculous Sine Missiles: If you have ever viewed the graph of sin(x), you'll see a nice flowing curve. When someone posted that they wanted to see missiles fly to their target in non linear paths, I decided to try it -- and thanks to javascript, I succeeded. Sin Missiles require two sets of equations and -- even worse, two weapons, two flingies, two sprites, and two images. One missile will be used for horizontal fire, and one will be used for vertical: Codevar fso = new ActiveXObject("Scripting.FileSystemObject"); var outputFileName = fso.GetParentFolderName(WScript.ScriptFullName) + "\\" + fso.GetBaseName(WScript.ScriptFullName) + ".icc"; var outputStream = fso.CreateTextFile(outputFileName, true); //functions function calculateyaxis(yaxis, distance) { yaxis = 4 * Math.round(Math.PI * Math.sin(180 * distance / Math.PI)); return yaxis; } // Program entry point for(var currentDistance = 0; currentDistance < 9; currentDistance += 1) { outputStream.WriteLine(" sethorpos " + calculateyaxis(0, currentDistance)); outputStream.WriteLine(" sprul 998 " + calculateyaxis(0, currentDistance) + " 0 # MissleTrail (thingy\smoke.grp)"); outputStream.WriteLine(" wait 1"); } outputStream.Close(); Codevar fso = new ActiveXObject("Scripting.FileSystemObject"); var outputFileName = fso.GetParentFolderName(WScript.ScriptFullName) + "\\" + fso.GetBaseName(WScript.ScriptFullName) + ".icc"; var outputStream = fso.CreateTextFile(outputFileName, true); //functions function calculateyaxis(yaxis, distance) { yaxis = 4 * Math.round(Math.PI * Math.sin(180 * distance / Math.PI)); return yaxis; } // Program entry point for(var currentDistance = 0; currentDistance < 9; currentDistance += 1) { outputStream.WriteLine(" setvertpos " + calculateyaxis(0, currentDistance)); outputStream.WriteLine(" sprul 998 0 " + calculateyaxis(0, currentDistance) + " # MissleTrail (thingy\smoke.grp)"); outputStream.WriteLine(" wait 1"); } outputStream.Close(); Now, copy + paste the output of the first one into an image that is unsed and do the same with the second one. Now, let's go to the Valkyrie and give it two weapons -- one air and one ground -- and have the weapons use "Flies to Target" and have it use a flingy that uses a sprite that uses the images that we editted. Now, go to the Valkyrie's iscript and change its attack to this: CodeValkyrieAirAttkInit: ValkyrieGndAttkInit: wait 1 curdirectcondjmp 0 22 FireBlock1 curdirectcondjmp 64 44 FireBlock2 curdirectcondjmp 128 22 FireBlock1 curdirectcondjmp 192 44 FireBlock2 EndofAttack: gotorepeatattk goto ValkyrieLocal00 ValkyrieLocal00: wait 125 goto ValkyrieLocal00 FireBlock1: wait 1 attackwith 1 wait 1 #useweapon 123 waitrand 10 12 goto EndofAttack FireBlock2: wait 1 attackwith 2 wait 1 #useweapon 125 waitrand 10 12 goto EndofAttack Compile everything and you get a Valkyrie that now fires sinMissiles! What is curdirectcondjmp?: While I'm at it, I shall diescribe how curdirectcondjmp works (thanks to Lord_Agamemnon). curdirectcondjump detects which way the unit is facing and jumps to a block of code if it is facing the right direction. The first number describes what angle it is at. A circle in SC is split into 256 units (not 360). So, to convert: Degress * 256 / 360 = Starcraft Measure Now the second number allows for error, giving a range clockwise and counter-clockwise of this Starcraft measure from the first number. curdirectcondjmp 64 44 FireBlock2 90 Degrees with about 61 degrees left or right of error allotment. (29d to 151d) Commplete generators and codes needed: var outputFileName = fso.GetParentFolderName(WScript.ScriptFullName) + "\\" + fso.GetBaseName(WScript.ScriptFullName) + ".icc"; var outputStream = fso.CreateTextFile(outputFileName, true); //functions function calculateyaxis(yaxis, distance) { yaxis = 4 * Math.round(Math.PI * Math.sin(180 * distance / Math.PI)); return yaxis; } // Program entry point for(var currentDistance = 0; currentDistance < 9; currentDistance += 1) { outputStream.WriteLine(" sethorpos " + calculateyaxis(0, currentDistance)); outputStream.WriteLine(" sprul 998 " + calculateyaxis(0, currentDistance) + " 0 # MissleTrail (thingy\smoke.grp)"); outputStream.WriteLine(" wait 1"); } outputStream.Close(); var outputFileName = fso.GetParentFolderName(WScript.ScriptFullName) + "\\" + fso.GetBaseName(WScript.ScriptFullName) + ".icc"; var outputStream = fso.CreateTextFile(outputFileName, true); //functions function calculateyaxis(yaxis, distance) { yaxis = 4 * Math.round(Math.PI * Math.sin(180 * distance / Math.PI)); return yaxis; } // Program entry point for(var currentDistance = 0; currentDistance < 9; currentDistance += 1) { outputStream.WriteLine(" setvertpos " + calculateyaxis(0, currentDistance)); outputStream.WriteLine(" sprul 998 0 " + calculateyaxis(0, currentDistance) + " # MissleTrail (thingy\smoke.grp)"); outputStream.WriteLine(" wait 1"); } outputStream.Close(); # This is a decompile of the iscript.bin file 'data\scripts\iscript.bin' # created on: Fri Jun 16 20:57:22 2006 # ----------------------------------------------------------------------------- # # ----------------------------------------------------------------------------- # # This header is used by images.dat entries: # 939 Valkyrie (terran\bomber.grp) .headerstart IsId 362 Type 12 Init ValkyrieInit Death ValkyrieDeath GndAttkInit ValkyrieGndAttkInit AirAttkInit ValkyrieAirAttkInit Unused1 [NONE] GndAttkRpt ValkyrieGndAttkInit AirAttkRpt ValkyrieAirAttkInit CastSpell [NONE] GndAttkToIdle ValkyrieGndAttkToIdle AirAttkToIdle ValkyrieGndAttkToIdle Unused2 [NONE] Walking ValkyrieWalking WalkingToIdle ValkyrieWalkingToIdle SpecialState1 [NONE] .headerend # ----------------------------------------------------------------------------- # ValkyrieInit: imgul 940 0 5 # ValkyrieShad (terran\bomber.grp) playfram 0x00 # frame set 0 goto ValkyrieGndAttkToIdle ValkyrieGndAttkToIdle: setvertpos 1 waitrand 8 10 setvertpos 2 waitrand 8 10 setvertpos 1 waitrand 8 10 setvertpos 0 waitrand 8 10 goto ValkyrieGndAttkToIdle ValkyrieDeath: playsnd 1040 # Terran\FRIGATE\TVkDth00.WAV imgol 332 0 0 # TerranBuildingExplosionsmall (thingy\tBangS.grp) wait 3 end ValkyrieAirAttkInit: ValkyrieGndAttkInit: wait 1 curdirectcondjmp 0 22 FireBlock1 curdirectcondjmp 64 44 FireBlock2 curdirectcondjmp 128 22 FireBlock1 curdirectcondjmp 192 44 FireBlock2 EndofAttack: gotorepeatattk goto ValkyrieLocal00 ValkyrieLocal00: wait 125 goto ValkyrieLocal00 FireBlock1: wait 1 attackwith 1 wait 1 #useweapon 123 waitrand 10 12 goto EndofAttack FireBlock2: wait 1 attackwith 2 wait 1 #useweapon 125 waitrand 10 12 goto EndofAttack ValkyrieWalking: imgol 249 0 0 # ValkyrieOverlay (thingy\tbmGlow.grp) sigorder 64 setvertpos 0 goto ValkyrieLocal00 ValkyrieWalkingToIdle: orderdone 64 goto ValkyrieGndAttkToIdle *Original Generators and Codes thanks to A_of_s_t -- who ownz at mathematics. |
||
|
This post was edited 2 times, last edit by A_of-s_t: Mar 25 2008, 4:54 am.
![]() From silent: "lolol First of all wikipedia is flawed because anyone can come into it and post anything. About criticism.. no. You can't just change the definition of a word and expect everyone to bow down in awe. I am using macro evolution as an identifier between changing from one kind to another kind. I.E. bananas turning into flies. So if you want to argue about this then your argueing about the definition of a word.. Not the theory itself. If you want I can use false evolution, or neverbeenseenbefore evolution instead of macro. Its up to you" This is stupidity. Please look at it very closely -- notice that almost every logical fallacy is used in it. |