Help with this noob error please.
-
@Chazrox said in Help with this noob error please.:
Is there a hierarchy in placement of 'var's and const's in respect to functions? Can I declare those anywhere in the script as long as its not inside of a block of code (with the exception of locals's)?
inline functions, const and vars can be declared before or after they are referenced. But regular functions need to be declared before they are referenced.
Note that you should try to use const and reg instead of var whenever possible to increase performance.
-
@hujackus how do they increase performance? Is there a big difference in cpu usage?
-
-
@d-healey I have watched your 101 Tutorial 3 times with extensive notes.....but expect me to make alot of mistakes until I dont. ha. Soakin it in...
-
@d-healey thank you
-
@Chazrox @d-healey There are a surprising amount of cases to consider when choosing variables and functions. I made a test to show some of the problems that occur when the wrong keywords are used or used at the wrong time.
Console.clear(); //testGlobal = undefined; //uncomment to explore what happens //testGlobal2 = undefined; //uncomment out to explore what happens //test(); //doesn't compile (This expression is not a function!) testInline(); const TEST_ARRAY = [5]; const TEST_CONST = 6; global testGlobal = 7; reg testReg = 8; var testVar = 9; function test(){ var t = ""; t += TEST_ARRAY[0]; t += TEST_ARRAY_2[0]; t += TEST_CONST; t += TEST_CONST_2; t += testGlobal; t += testGlobal2; t += testReg; t += testReg2; t += testVar; t += testVar2; Console.print("test():"+t); Console.print(TEST_ARRAY[0]); // Console.print(TEST_ARRAY_2[0]);//doesn't compile (API call with undefined parameter 0) Console.print(TEST_CONST); // Console.print(TEST_CONST_2);//only compiles if TEST_CONST_2 was defined in a prev compile Console.print(testGlobal); // Console.print(testGlobal2); //only compiles if testGlobal2 was defined in a prev compile Console.print(testReg); // Console.print(testReg2); //doesn't compile (API call with undefined parameter 0) Console.print(testVar); // Console.print(testVar2); //doesn't compile (API call with undefined parameter 0) }; inline function testInline(){ local t = ""; t += TEST_ARRAY[0]; t += TEST_ARRAY_2[0]; t += TEST_CONST; t += TEST_CONST_2; t += testGlobal; t += testGlobal2; t += testReg; t += testReg2; t += testVar; t += testVar2; Console.print("testInline():"+t); // Console.print(TEST_ARRAY[0]); //doesn't compile (API call with undefined parameter 0) // Console.print(TEST_ARRAY_2[0]);//doesn't compile (API call with undefined parameter 0) Console.print(TEST_CONST); Console.print(TEST_CONST_2); // Console.print(testGlobal); //only compiles if testGlobal was defined in a prev compile // Console.print(testGlobal2);//only compiles if testGlobal2 was defined in a prev compile // Console.print(testReg); //doesn't compile (API call with undefined parameter 0) // Console.print(testReg2); //doesn't compile (API call with undefined parameter 0) // Console.print(testVar); //doesn't compile (API call with undefined parameter 0) // Console.print(testVar2); //doesn't compile (API call with undefined parameter 0) }; test(); testInline(); const TEST_ARRAY_2 = [25]; const TEST_CONST_2 = 26; global testGlobal2 = 27; reg testReg2 = 28; var testVar2 = 29; test(); testInline();
or in snippet form
HiseSnippet 1126.3oc2W01ahbCD1KIaUg9h5I0OzO5luTnWUOfRBjFE0KgPthZSBJPiZUzIjiWSv5L1q10jbnS4+b+GzN1KaX2vB4DjnJ08KKddwyiGOOKyzIPQYggp.jSgdS7YHmO2s6DodXygDtD09HjyW5dBITyBvQhNbhOILj4gbb13MFAN42DYe96e4PhfHorYhPnKTbJ624i35YR675eiKDGS7X83iRXcsW2lpjMUB0X.Oa3VF4SnuibM6ThwrbtnekDND478tdUpUYPCJYmFUpUkRq1nd0cqSYjACX6TY650ZLn1.BsbUjymzxiqUAc0DMKD4r4gJuIcGptUFEfK3g7qDLyhJntPjiDerR3YNhFonlC4BuNwIpPDrKclk11HJs80tmv832KeV56qrJvy7HYBzIWZ3sQJ3UII7Jm.dY.ImDPZyHH8B2tz.tudlFCd9L21R31DROrTPIxVTtuofKtoRFpDrejJXjfhk1q.9UuBvm9MB0UDAde7XoGa.Wx71CzLVRUiFwjZrVgYu2WnBX3aGRz3gDeelLLs6UWr+pwKYOh2E.Ovu7TrP42owfq9bACWr2Pdnwy.3nxURLrRpzXBd.r+ZPx2Vp.13eao.hr8TU.bWFpw8Z0sW+CN+7C9K.aWt8a2KkhlmcZ2dfhc.wWGkARkLpCxCXWaEdN7debCPxMj.qjKf26i20FsXnfiNGen.Nu0Lvfs1BrHuF+x8SflKK+1Lj1u5bxsPLCQ8qduvYPNCQoMCNDObcZCfyzCWaMHttwOfK0E2J5T9ya8RsIYmeNCRcPipxVnE1Cco8x3h+fNswThPfukqGNqxB6SBfOaX9vU4RYGZaJZwwcZFzDTkTLINhgX9fToX7sjPbbT4RnjCJBuI174B8rrdlgNwkhsPetPmjI8HQNqPCWlKLtlKZHnvySUddZ0wBinoxYMi3cvdysb5z7qXdtgkITTCq8+w7r3SaLaaojIKUZMR4+WwSWJKcoboGiJ8XLokSSWOV5hnhqIuX4L7m1s0RwwOGa6Zh16rTgosM7Q7++8McmbY0LaAvpqZlcAX07f9.rxdPm.VY6tTLc+2vTxSUZ1YxhkJ7gB4Kb27pFLHScPdTGnDBVPlpM8bGrLGKJGO5JVvO..WLlcugPekoaV0cwMqlrWZHMpgl6RXnR1Vx0mAs0snNrQMibB90ez9HhlX5vcpLvNeVflaffyQraf4Kh52Mu6Qrv2oU9vDFy0LLzFtxarfnS2atYBloJfbPpFhMsIKC45IImv4Iqg8OVH9B2NbMcX1XLWFXDxTOGXb5XNegaKXFKpdF.2z83+74YlFz4v7.b40mPzA72C0amNdTWXzPJChtTxDlZPmblpkn0kMqMYftLomcw+.OSUVwr1YpxJwJQiHz.UeZTkuYPpO0JAvjzNzYdX5WXMtBxxFRlmGAy00mRSuUy4X0U0weZUcr1p531qpi6rpNVeUcrwi6nYr6CFqUihnMHzIcZY+ThiSKIAp.sUqn+Eg0SCJA
-
@mmprod said in Help with this noob error please.:
how do they increase performance? Is there a big difference in cpu usage?
There is a difference when you have a lot of variables. If you use the var keyword for all your variables, when your program references a variable at runtime the program has to search for the location in memory that variable refers to using a dictionary/hash lookup table.
If you use const or reg, these variables are optimized at compile time to work more like indexing an array, which is much quicker. If I'm wrong, I would like to know a better explanation.
-
@hujackus Im not sure how to apply this.
-
This is why I asked. I've been trying to practice different scripts. My code gets long and things that were working before stop working. My assumption is the order that its placed. Its easy for me to understand writing 1 block of code but as soon as I start writing past that things stop working. Here's an example of painting an image onto a panel. I did the first scope correctly because the image shows up on the panel. I assumed I can just rewrite the same exact code under it and replace the names for the new panels and images and it would work but for some reason the second image>panel is not drawing. Help me understand the Logic. I've been watching hours and hours of scripting videos for HISE and c++ so im up to my nose in it. I feel like I just need a little more insight if you guys can get what im saying and give me a nugget or two. Appreciate you guys!
-
@Chazrox Check your spelling on line 26.
-
@d-healey frik. Thank You sir.
-
@Chazrox said in Help with this noob error please.:
Im not sure how to apply this.
That's ok. I just made a code example that would have helped me a month ago when I started learning "HISEscript". By uncommenting each line, you can see the differences in behavior for each combination of keywords used.