Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
twcore issues.
Goto page Previous  1, 2
 
Post new topic   Reply to topic Printable version
 View previous topic  LVZ toggling with mervbot Post :: Post Player Position packet weapons question  View next topic  
Author Message
SamHughes
Server Help Squatter


Joined: Jun 30 2004
Posts: 251
Location: Greenwich
Offline

PostPosted: Sat Apr 16, 2005 2:08 pm    Post subject: Reply to topic Reply with quote

Oh right, this is Java. Didn't notice that little "public" at the top of the function.

At any rate, in this case, the efficiency of Strings doesn't matter, since putting a player's location into human-readable letter-number coordinates is the sort of task that happens only once per user interaction.

Mr. Ekted wrote:
Whenever "a" is assigned a non-null value, memory is allocated. The return value is a string that needs to be created (allocated)--twice! And when the return value is assign back in the calling function, another allocation takes place. This is retarded.


I would call the programmer retarded, not the class. (Then again, looking at the way MERVbot's String class handles growing strings, I might reconsider calling the class retarded anyway.)

[Edit: Never mind. I just looked at the MERVbot String class's source code, and I would have to agree that it is something to be avoided. The class is indeed moronic. The standard library string class is much better.]
Back to top
View users profile Send private message Add User to Ignore List
wiredfreak
Newbie


Age:50
Gender:Gender:Male
Joined: Apr 14 2005
Posts: 14
Offline

PostPosted: Sat Apr 16, 2005 3:21 pm    Post subject: Reply to topic Reply with quote

Ok. How about this...

Code: Show/Hide

public String getCoords(Player p) {
   return =""+
      ((char)(65+((p.getXLocation() * 5 ) >> 12)))+
      (((p.getYLocation() * 5 ) >> 12) + 1);
}


Is THIS efficient enough?

-wf
Back to top
View users profile Send private message Add User to Ignore List MSN Messenger
SamHughes
Server Help Squatter


Joined: Jun 30 2004
Posts: 251
Location: Greenwich
Offline

PostPosted: Sat Apr 16, 2005 3:46 pm    Post subject: Reply to topic Reply with quote

Does it compile? There is an equals sign there. I don't know Java very well. The example I gave you was me thinking in C++ code for the MERVbot.

If it works, it would be efficient enough. The efficiency is not too important.
Back to top
View users profile Send private message Add User to Ignore List
Cerium
Server Help Squatter


Age:42
Gender:Gender:Male
Joined: Mar 05 2005
Posts: 807
Location: I will stab you.
Offline

PostPosted: Sat Apr 16, 2005 4:35 pm    Post subject: Reply to topic Reply with quote

Using "" to cast that statement into a string is what ekted was talking about. If youre really hellbent on making that efficient, use StringBuffer.

Oh yeah, and that equals sign will break it =)

Code: Show/Hide

public String getCoords(Player p) {
   return new StringBuffer(3).append( ((char)(65+((p.getXLocation() * 5 ) >> 12))) ).append( (((p.getYLocation() * 5 ) >> 12) + 1) ).toString();
}


That is assuming, of course, that the blocks inside the append( ... ) are correct.

-C
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sat Apr 16, 2005 4:52 pm    Post subject: Reply to topic Reply with quote

wiredfreak wrote:
Is THIS efficient enough?

-wf


Not even close.
_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
SamHughes
Server Help Squatter


Joined: Jun 30 2004
Posts: 251
Location: Greenwich
Offline

PostPosted: Sat Apr 16, 2005 6:24 pm    Post subject: Reply to topic Reply with quote

This conversation is getting absurd.

"Efficient enough" means that the program works fast enough for the user not to notice. Outputting coordinates in string form is a rarely executed task, and a few milliseconds aren't going to hurt anybody.
Back to top
View users profile Send private message Add User to Ignore List
wiredfreak
Newbie


Age:50
Gender:Gender:Male
Joined: Apr 14 2005
Posts: 14
Offline

PostPosted: Sat Apr 16, 2005 6:51 pm    Post subject: Reply to topic Reply with quote

Sam & Cerium... doh. Yea, the equals wasn't supposed to be there. icon_smile.gif Me and my typos. heh.

Sam... Hehe... Yea, well, I'm trying to learn a little more about this... even if it doesn't get executed often enough to matter... it helps me.

There's more than one way to do anything... But you're right, Sam. icon_smile.gif

-wf
Back to top
View users profile Send private message Add User to Ignore List MSN Messenger
Underlord
Novice


Gender:Gender:Male
Joined: Feb 17 2004
Posts: 55
Offline

PostPosted: Sun Apr 17, 2005 8:48 am    Post subject: Reply to topic Reply with quote

Code: Show/Hide

char str[4];

sprintf(str,"%c%d%c",char('A' + x * 20 / 0x400),(y * 20 / 0x400) + 1,0);
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sun Apr 17, 2005 9:53 am    Post subject: Reply to topic Reply with quote

Much better, but I would even go further. Sprintf is overkill.

Code: Show/Hide

char str[3];

str[0] = 'A' + x * 20 / 0x400;
str[1] = y * 20 / 0x400 + 1;
str[2] = 0;
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sun Apr 17, 2005 10:50 am    Post subject: Reply to topic Reply with quote

Remember, Ek, this is Java. No char arrays for strings.

Also, I think Ekted talked earlier about the right shift. Please, don't do multiplication like that. The compiler will optimize that for you, and it just makes the code less readable.
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sun Apr 17, 2005 12:59 pm    Post subject: Reply to topic Reply with quote

Yes, but even in Java you could return the coords as two integral values and let any code that wants to display human-readable location format it how it likes.
Back to top
View users profile Send private message Add User to Ignore List
wiredfreak
Newbie


Age:50
Gender:Gender:Male
Joined: Apr 14 2005
Posts: 14
Offline

PostPosted: Tue Jun 07, 2005 9:19 pm    Post subject: TWCore crashes when logged in as SMod Reply to topic Reply with quote

Alright. More TWcore issues. I'm using the latest... TWCore 0.89

I'm just getting back into coding the bot I was working on way back when this topic was created.... So... it's still related.

Here's the issue.... If the bot is logged in as Sysop, there's no problem... HOWEVER.... if I log the bot in as an SMod... The whole thing comes crashing down if ?cheater or any similar command is used which displays a ?cheater type message.

When turning verbose on, I get the following thread of messages:

Tue 05-07-2005 08:07:51 slavebot is logging in.
slavebot logged in: 60 ms.
[Loaded java.lang.IndexOutOfBoundsException from C:\j2sdk1.4.2_07\jre\lib\rt.jar]
[Loaded java.lang.StringIndexOutOfBoundsException from C:\j2sdk1.4.2_07\jre\lib\rt.jar]
Tue 05-07-2005 08:07:54 slavebot is disconnecting...
Tue 05-07-2005 08:07:54 masterbot is disconnecting...
[Loaded java.lang.Shutdown from C:\j2sdk1.4.2_07\jre\lib\rt.jar]
[Loaded java.lang.Shutdown$Lock from C:\j2sdk1.4.2_07\jre\lib\rt.jar]


How do I fix the core so that it can be logged in as SMod instead of Sysop?

-wf
Back to top
View users profile Send private message Add User to Ignore List MSN Messenger
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Tue Jun 07, 2005 10:51 pm    Post subject: Reply to topic Reply with quote

I'm going through this right now along with some other dev team people, would you happen to have any specific information such as line numbers from the stack trace?

AFAIK, the bot has to be sysop anyways for most stuff to work in the current setup

EDIT: probably has something to do with this:
Code: Show/Hide
if( m_messageType == Message.ARENA_MESSAGE && m_message.startsWith( "misc:alertcommand:" )){
    alertCommands = m_message.substring( 18 ).split( "," );

_________________

Back to top
View users profile Send private message Add User to Ignore List Visit posters website
wiredfreak
Newbie


Age:50
Gender:Gender:Male
Joined: Apr 14 2005
Posts: 14
Offline

PostPosted: Tue Jun 07, 2005 11:59 pm    Post subject: Reply to topic Reply with quote

Unfortunately, this is the only information returned at the point of failure....

However... After mussing with the runbots.bat file and just generally screwing with things.... I tried the following batch command:

java -cp twcore.jar;twcore/misc/googleapi.jar;twcore/misc/mysql-connector-java-3.0.6-stable-bin.jar -verbose -Xdebug twcore.core.Start

What EXACTLY this did to my core execution... I do not know.... However... I know that I STILL get the messages *on the first reception* of the ?cheater type messages... but not again after... and the bot no longer craters.

I can't tell you why this works for me, but it's what I did. Also, since I'm *ONLY* using this to *TEST* and develop my bot before giving it to the owner of the zone to run on his own core bot... I do not need the additional functionality that sysop access grants. That's the primary reason I need this to run as SMod, since I'm only a writer for another zone.

I still have a lot to learn... I'm not an expert at all... but I like to believe I can at least stumble my way through a problem when I need to. icon_smile.gif

-wf
Back to top
View users profile Send private message Add User to Ignore List MSN Messenger
SamHughes
Server Help Squatter


Joined: Jun 30 2004
Posts: 251
Location: Greenwich
Offline

PostPosted: Fri Jun 10, 2005 4:35 pm    Post subject: Reply to topic Reply with quote

Mr Ekted wrote:
No commercial app that handles large amounts of text (Notepad, Wordpad, Word, Excel, VisualStudio, IE, Netscape, Firefox, OpenOffice Write, etc) would be caught dead using String.


Firefox uses string classes. There are a few string-related classes in there. But they don't use Mervbot's String class icon_smile.gif
Back to top
View users profile Send private message Add User to Ignore List
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Sat Jun 11, 2005 3:56 pm    Post subject: Reply to topic Reply with quote

I figured out why the alert command thing doesn't work and I should have it fixed when we get our next release out (whevener that is sa_tongue.gif). What happens is it uses *g* to get the alert commands and since it returns nothing if you're smod it goes out of bounds when looking up by index. If its gonna be too long before an official release, I'll put up a patch on my site.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can 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
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 97 page(s) served in previous 5 minutes.

phpBB Created this page in 0.543349 seconds : 40 queries executed (78.1%): GZIP compression disabled