Log In  

Today I was playing with string management and thought: "If strings now work kinda like tables, maybe pairs() can work with them", but seems that it can't...

for p, i in pairs(code) do

Note: I am on education edition

P#118909 2022-10-11 17:39

If someone didn't understand, the bug is on the error message, and if it happens with this code, maybe can happen with other too, in situations that aren't clear

P#118910 2022-10-11 17:41 ( Edited 2022-10-11 17:42)

For a more minimal example, running just this code by itself:

for p,i in pairs("ssss") do

results in this message

in pairs line 0 (tab 0)
at line 1 (tab 0)

I got curious and checked if all() has similar behavior. Replacing pairs() with all() and supplying only 1 variable results in printing the characters one after another and then printing a blank string endlessly.

Also checked count() inside print() to see what occurs. It returns without printing anything.

Lastly, foreach() used with a string and print as the function results in the same behavior as using all.

P#118912 2022-10-11 18:15

I didn't checked all that things, but I tested with all() and got everything alright. I think I broke the loop before it happens. Thanks for test everything, found a error in the code.

P#118914 2022-10-11 18:25

@biteco8, please change the TOPIC away from "bugs" to "chat" or something else if you are satisfied with the solution - so ZEP won't be seeing and trying to correct this problem as it is listed such.

Thanks !

P#118918 2022-10-11 19:53

No, I found a specfic problem in my code, the error mensages are still buggy. The problem isn't in my code, is on the error log. See the first image.

P#118928 2022-10-11 23:16

Realistically, @biteco8, you'd want to be using ipairs("..."), not pairs("..."), since a string is an ordered sequence that's keyed purely by integers. Though, sadly, that doesn't work either.

That being said, I did just make a post to suggest to @zep that he return nil for out-of-bounds string accesses, because I think that would make the almost-working all("...") iterator that @kimiyoribaka discovered work.

P#119530 2022-10-25 00:58 ( Edited 2022-10-25 01:00)

[Please log in to post a comment]