KevKelley Posted May 22, 2020 Share Posted May 22, 2020 I was trying to find ways to get more space in my game. I have been avoiding adding additional banks to force myself to learn some tricks, so to speak. I noticed that when I swapped something like this: temp5=(rand&3)+20 into this: const c_R3=rand&3 temp5=(c_R3)+20 it saved 30 bytes but I did not see any difference in performance. I was wondering if anyone understood the reason as to why. I was looking up through the forums and Random Terrain's site but saw nothing that indicated why. I assume it is just how it compiles? Quote Link to comment Share on other sites More sharing options...
KevKelley Posted May 22, 2020 Author Share Posted May 22, 2020 Now I had noticed that in some instances it would generate the same number each time, like with the temp variables. Would this because they are wiped each frame and the constant draws up the same number in the same order the next time it is called? Quote Link to comment Share on other sites More sharing options...
+Karl G Posted May 22, 2020 Share Posted May 22, 2020 You can't set a const to a random value. What you are doing in this case is taking the memory address of the "rand" declaration, doing a bitwise AND of 3, then adding 20 to the value, so this will have the same value every time. The rand function never gets run in this case. 2 Quote Link to comment Share on other sites More sharing options...
KevKelley Posted May 22, 2020 Author Share Posted May 22, 2020 Ah. I see. I just went through to see why I thought it was working and I noticed that there was one line where I didn't replace the rand command so it seemed like it was random, but it was just one of the coordinates. Had I ran it longer I probably would have noticed my mistake when everything would spawn in a column. So I guess the 30 bytes I saved was it not running rand at all then and not some magic trick. Darn. I must have missed somewhere where it stated constants cannot set const to a rand value. Thanks! Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted May 22, 2020 Share Posted May 22, 2020 I think const and def are more or less doing a text substitution swap before compilation. Using that assumption not sure how the space savings is happening. Quote Link to comment Share on other sites More sharing options...
Lillapojkenpåön Posted May 22, 2020 Share Posted May 22, 2020 (edited) 20 minutes ago, Gemintronic said: I think const and def are more or less doing a text substitution swap before compilation. Using that assumption not sure how the space savings is happening. def does, const needs to be a value I guess, not code Edited May 22, 2020 by Lillapojkenpåön 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.