User defaults not read when using repeat loop to read them.

Hi everyone,

I was trying to save some space (and speed) in my code. Instead of using multiple times the make new default entry thing :

tell user defaults
	make new default entry at end of default entries with properties {name:theDefaultEntry, contents:theVariable}
	set theVariable to contents of default entry theDefaultEntry
	make new default entry at end of default entries with properties {name:OtherDefaultEntry, contents:OtherVariable}
	set OtherVariable to contents of default entry OtherDefaultEntry
end tell

-Which does seem to work with my code, the defaults are read. So no problems with writing user defaults etc.

But this doesn’t, I tried moving the tell block inside the repeat loop and back out but it does not seem to read my preferences.

tell user defaults
	repeat with i from 1 to 6
		set theVariable to item i of {var1, var2, var3, var4, var5, var6}
		set theDefaultEntry to item i of {"def1", "def2", "def3", "def4", "def5", "def6"}
		make new default entry at end of default entries with properties {name:theDefaultEntry, contents:theVariable}
		set theVariable to contents of default entry theDefaultEntry
	end repeat
end tell

Nothing seems to happen not even an error popping up. Is this default behavior of the defaults?

Thanks

Wouldn’t adding a repeat statement make it slower?

It seems to read just fine for me.

I tried Nigels’ lotsa routine and it’s about the same. Since I can’t repeat it a few times to have more consistent results I don’t know if there is difference in time.

But if it works with you, I’m sure it’s something wrong with me and I’ll try to fix it. Guess I’ll just use them without repeat loops if I can’t.

Thanks :slight_smile: