TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

possible array code bug

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
lilmike



Joined: 08 Feb 2015
Posts: 9
Location: Baton Rouge, Louisiana

PostPosted: Sun Feb 08, 2015 8:13 pm    Post subject: possible array code bug Reply with quote

Hi,
I have been working on the tintin-alteraeon (https://github.com/stormdragon2976/tintin-alteraeon) code, and one thing I noticed that seems odd is the following:

When you set an array at index 1, then later set the index 2 in the same array, it will somehow erase, clear, or otherwise make blank index 1. For example, some rough code follows:

Code:

#variable {something} {hello};
#variable {something2} {{1}{${something}}};
#variable {something} {goodbye};
#variable {something2} {{2}{${something}}};
#variable something2;


This should result in an array of {{1}{hello}{2}{goodbye}}, but instead it results in {{2}{goodbye}}
This seems odd, as how could you, say, loop through an array an copy its elements to another array without having to put something like {{1}{something}{2}{somethingelse}{3}{somethingsomethingelse}} every single time you went through the loop?
Thanks,
-Michael.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Mon Feb 09, 2015 5:25 pm    Post subject: Reply with quote

In this particular case you can use #list

Code:

#variable {something} {hello};
#list {something2} {add} {${something}};
#variable {something} {goodbye};
#list {something2} {add} {${something}};
#variable something2;


anyway I find that also the #list command has something strange to me:
Code:

#variable {something} {hello};
#list {something2} {insert} {1} {${something}};
#variable {something} {goodbye};
#list {something2} {insert} {2} {${something}};
#variable something2;


in this case it should result {{1}{hello}{2}{goodbye}} but instead it result reversed {{1}{goodbye}{2}{hello}}

as every not already existent slot is created as the first one...
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Mon Feb 09, 2015 5:38 pm    Post subject: Reply with quote

Can try:

#variable {something2[2]} {${something}}

That way you don't overwrite the variable.


When using #list insert it must be a valid index, and index 2 isn't valid in your example, so it's the equivalent of inserting at index 1.
Back to top
View user's profile Send private message Send e-mail
lilmike



Joined: 08 Feb 2015
Posts: 9
Location: Baton Rouge, Louisiana

PostPosted: Fri Mar 06, 2015 11:02 pm    Post subject: Reply with quote

Ok, I see how you can add to an index without overwriting it now. Thanks for the clarification. Btw sorry for getting back so late, for some reason the forum didn't email me the new replies even though I told it to for this topic haha.
-Michael.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group