|
|
|
|
Reply From: |
SIsilicon |
You know you could store the commands and parameter in an array.
For example: ['poly_line', [Vect...], Color.., 'draw_line', Vec.., Vec.., Color..]
That’s draw_poly_line with a Vector2 array and color, and then a regular line with three parameter after.
In the draw function you can then read this array using a match statement within a while loop.
var i = 0
while i < commands.size():
match commands[i]:
'poly_line':
draw_poly_line(commands[i+1], commands[i+2])
i += 3
'draw_line':
draw_line(commands[i+1], commands[i+2], commands[i+3])
i += 4
_: printer('Sry.. Unknown command at ' + str(i) + ' :(')
And you can add more to it.
So how does this help? Well now you can easily call a specified number of these commands. Simply by replacing commands.size()
in the while loop with min('your_var', commands.size()
.
Any questions?
That’s a very interesting way of doing it. I think I wouldn’t be able to come up with that by myself, at least not at this level of experience (this is my first public programme).
Have you come up with that or have you learnt it? If you learned it, can I know the book/person you learned it from?
And also, let me understand;
First of all, is match the same or similar to the switch command in C++?
Next, what is the min function and what does it do?
Also, the “_” at the end gets executed when i is not between 0 and commands.size()?
Even one more question, if commands[1] is an array, you could access the different values of that array by typing commands[1][comment0-x], or [1,x]?
I just really found this way of doing this very interesting and want to know everything about it.
So, with this code, I could go from the 0.1 figure to the .2 figure, to .3, and so on.
Wouldn’t this draw the new shape over the old one, which would make it not look so good?
And how could I make this be able to change the speed at which it draws the new figure. For example make it either 30 fps, or 10 fps or so.
Thank you very much for you reply, have a great day!
C:\Flavius | 2018-05-19 16:54
Ok. exhales heavily
Here we go.
Have you come up with that or have you learnt it?
Came up with it right on the spot. Which also means it’s prone to error so I’ll be testing it as well.
First of all, is match the same or similar to the switch command in C++?
Indeed it is. With only a few differences.
Next, what is the min function and what does it do?
It does as its name implies. Returns the minimum of two of its parameters. In this case, your variable, and the size of the command array. Eg: min(1, 2) = 1; min(9, 7) = 7;
Also, the “_” at the end gets executed when i is not between 0 and commands.size()?
Nope. It is the equivalent of default
in switch-case
. Meaning that it is the only one that will match if none of the others match. So in this case, if the command does not match neither ‘poly_line’ nor ‘draw_line’ then it will match with _. And thus in our case again, print an error.
Even one more question, if commands[ 1] is an array, you could access the different values of that array by typing commands[ 1][comment1-x], or [1,x]?
The first one. [ 1][comment1-x]
Wouldn’t this draw the new shape over the old one, which would make it not look so good?
Nope. All of this is inside the canvas item’s override able _draw()
function. It gets cleared every time it gets called(which is automatic so please don’t call it yourself). However to get to draw something different, you not only change the variable; but you must also call update()
every time the draw function changes in anyway. That includes the variables it uses.
And how could I make this be able to change the speed at which it draws the new figure. For example make it either 30 fps, or 10 fps or so.
By changing how much you increment ‘your variable’ by. Like increment it by 0.016 * 20 every frame.
Unfortunately though, my current code does not interpolate lines. Instead it does each command in its entirety. Going to have to use more brain power to figure that out …
SIsilicon | 2018-05-19 18:00
Thanks a lot for all this help!
One more question, why does it have to be multiplied by 20?
I’m playing with this right now, it seems it will work wonder.
So, correct me if I am wrong but the way this will work is that if, for example I choose my variable to be 0, and the increment to be 0.016 * 20, it will begin by drawing a simple circle (cause the first variable is 0) and then, the cardioid will slowly emerge. Right?
And if I want to stop it, can I just hit the “Return” button (one button I placed that gets you back to the main menu) or it will mess with the program?
Edit: I put all the variables and commands in an array, and used that code. Replaced commands.size() with min(0, commands.size());
So this way the first thing it draws is an empty circle, but it doesnt drawy anything.
Lol just realised before hitting Save Changes. i is not less then 0 so it doesn’t draw anything. I don’t know how to increment the variable, but I will figure it out. Omg I’m so noob
Edit2: changed the 0 to other number. It freezes, it doesn’t get any error, it’s just like it’s in an infinite recursion.
Edit3:
This is what I did
var increment = 0.32
var i = 0
while i < commands.size():
match commands[i]:
'draw_circle':
draw_circly(commands)
i += 5
'draw_epic':
draw_epicicles(commands);
commands[6] = commands[6] + increment;
i += 5
'restart':
update();
i = 0;
_: print('Sry.. Unknown command at ' + str(i) + ' :(')
So in my mind, this should draw a circle, then draw the epicycloid (the figures shown in the screenshots), then increase the variable (number of epicycles, or NbOfEpicycles) with 0.32 (0.016 * 20) and then restart i so that it draws everything again.
But it freezes, you know, as if it was doing an infinite loop, which now that I think of it, it’s doing so.
I just deleted the restart part, and it still freezes.
Where do I put the update thing?
Edit4: I’ve put the update() in many places, so yeah, I completely don’t know where to place it without the program freezing
C:\Flavius | 2018-05-19 18:22
Update() shouldn’t be called inside the draw function. Here’s what you could do. Call it every time you change a variable used by the draw function.
Also I don’t recommend passing the whole command array. Instead pass the parameters that come after the command. Which is why i
is incremented by a certain amount depending on the command’s number of parameters. So like if I had a command that had two parameters, then it would have two variables following the command in the array.
#Example
commands = ['my_func', 0.7, 6.8]
#my_func has two parameters. So it has two variables following it.
var i = 0
while i < commands.size():
match commands[i]:
'my_func':
#first parameter second parameter
my_func(commands[i+1], commands[i+2])
i is incremented by number of parameters + 1
i += 3
SIsilicon | 2018-05-19 19:12
Also maybe you should allow to help me with your project more directly.
Like host it on github or somewhere. I could help more.
SIsilicon | 2018-05-19 19:26
And I believe this is the only way I can help with that infinite freeze.
SIsilicon | 2018-05-19 19:28
That would be great, but how do I host the project in github? I think I need the files of the project, but where can I find them?
Also, I will try again, doing what you told me.
Edit: I changed the whole ‘commands’ variable to just the parameters I will use.
Well, now it is 10 PM here so I’m gonna go eat something, and then I may go to sleep.
I will host my project on GitHub tomorrow, thank you very much for all this help!
Have a nice day
C:\Flavius | 2018-05-19 19:38
Goodnight. Its 3:30 PM here
SIsilicon | 2018-05-19 20:30
…
Sooooo…
Did you get your project on github yet?
SIsilicon | 2018-05-23 03:24
Still no reply…
SIsilicon | 2018-06-01 14:41
@SIsilicon oh my god. I’m really sorry. I got completely absorbed by school.
I posted the source code on GitHub. This is the link: https://github.com/Fl4v1u5/Epikiklos
For some reason I could not upload the contents of the .import folder. I have uploaded this some days ago, I don’t know why I didn’t tell you.
Actually I made some graphic changes but the code is still the same.
sorry for not replying in soooo long.
C:\Flavius | 2018-06-03 12:26
I forgives you. School can be a time sucker.
SIsilicon | 2018-06-03 14:41
And I went ahead and made a fork. When I am in better internet, I will look into code, and see how I can help.
SIsilicon | 2018-06-03 18:59
Thanks a lot! I will check it right now!
C:\Flavius | 2018-06-07 19:18
So in the _process(delta) function you change some variable and then use update() to make it draw it again but with that changed variable?
I think I can do really cool stuff with that…
C:\Flavius | 2018-06-07 19:45
Yes, that’s right.
SIsilicon | 2018-06-07 19:54
Thank you very much for all your help!
C:\Flavius | 2018-06-08 16:17
HEYYYY!! I done something amazing, but for some reason it restarts everytime I move the mouse. Like, it goes from whatever it was on the screen to an empty circle and starts again everytime I move my cursor. How can I solve that? If you tell me I will show you what i’ve done, and you won’t regret it.
C:\Flavius | 2018-06-08 16:27
I’ll look into that.
Just tell me this. Is there any modifications to project that I need to know about?
SIsilicon | 2018-06-08 17:50
Yes, I took the old version of the project (aka, deleted all your changes) and then added a few things in the _process function to change the variable NbOfEpicycles and the colors, and also I made the screen bigger and added a different background but I don’t think that affects the program.
I mean, I will push the code to GitHub again, so you can see what I mean.
This is the changed project.
So I just analized what you did and realised this thing could be made.
To see what I mean just run the project, press space or enter and then watch what it does.
Please do not move the cursor or it will restart, and also I am still working in the colors to make them cycle.
C:\Flavius | 2018-06-08 18:11
Actually, the problem was very easy to find.
Inside your level scene’s circle drawer script. Line 10.
See, what’s happening is that you attempted to put all of the lines of code in one line with the if statement. That’s not how it works. The script compiler will only take the first command as part of the if statement.
#Inline if statements only work for one command.
if condition: a command; this other command is not part of the if statement
The rest gets called normally. So every time you move your mouse, click with it, press any key(besides enter), any input event at all. It will reset.
What you need to do is to put each command on a separate line with one tab more than the preceding if statement.
if condition:
a command
another command
etc...
This command isn't part of the if statement
SIsilicon | 2018-06-08 22:17
True! Thank you very much! Hahah I don’t remember why I did that xD thank you for all your help, have a nice weekend!
C:\Flavius | 2018-06-09 14:33
Same to you.
SIsilicon | 2018-06-09 17:17