You declared local RandomEntity = {}. That's one single table. Every time you call RandomEntity:new(), the value of self will always be that table, unless you reassign it again as I did.
I found the problem by printing something within the timer. The timer was only executed once, even if I expected it to be executed in pairs, and that hinted to the problem. Maybe you can use a similar technique. Print self inside the timer or at the points where you get the same random numbers, and see how many times they are executed. I no longer think this is a problem with the random generators.
Same randomness between instances of the same class
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- scissors61
- Citizen
- Posts: 76
- Joined: Fri Jan 08, 2016 10:16 am
Re: Same randomness between instances of the same class
Thanks, now I understand the use of the colon syntax better, and how it was an error in my code. I thought it was just a way of avoiding writing self, but it's more than that. While creating a function the colon syntax adds self as a parameter, but the weird thing if you use self as a table you don't have to write "self = {}" and there won't be an index table error.zorg wrote: ↑Fri Mar 02, 2018 10:57 pm The colon syntax implicitly adds a first parameter called self to the function definition in question, and when you call such a function, if that happens with the colon syntax as well, (iirc) the last table that contains the function itself will be passed into it as "self";
Yes, it is not a problem of random generators anymore. But even if I solved the problem in the example, I still cannot solve it in my code. I get the same tweens even if the randomness is different between instances. The problem of showing a piece of my code is that it is a very personalized structure that might be complicated to understand, but I'm going to post it anyways if anyone wants to check it. The code for the enemy is placed in src.modules.enemy, the class is created in src.Enemy, the instance of the entity/class is created at gamestates.random_enemy_gamestate
- Attachments
-
- personalized_unsolved.love
- (1.55 MiB) Downloaded 86 times
-
- solved_example.love
- (3.16 KiB) Downloaded 83 times
Re: Same randomness between instances of the same class
I added a print in the ball loading code, and it gets called twice. Similarly, the code to move the enemy is called twice per frame with two different tables. I don't know if that is normal, but it doesn't sound right.
It seems to me that at some point, the code is failing to distinguish the ball and the enemy, and it's treating the ball as both ball and enemy, and same for the enemy. No idea where, though.
It seems to me that at some point, the code is failing to distinguish the ball and the enemy, and it's treating the ball as both ball and enemy, and same for the enemy. No idea where, though.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 44 guests