Blizzhackers

Home of the Dupe since 2001

* Login   * Register    * FAQ    * Search

Join us on IRC: #bh@irc.synirc.net (or Mibbit Web IRC)


It is currently Tue Jun 27, 2017 1:11 am


All times are UTC [ DST ]





Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: help with a script
PostPosted: Tue Apr 18, 2017 10:37 am 
 
User
User

Joined: Wed Feb 04, 2015 12:17 am
Hey all

Need a little help.
In Misc.js - fileAction function, Im trying to add a function that will change the path of the file.
for some reason, im getting the error: "D2bs is not responding... restarting profile"

here is what i wrote,

fileAction: function (path, mode, msg) {
      var i,
         contents = "";
      if(me.profile.indexOf("_2") && path.indexOf("message_logs")){
         path = this.newPath(path);
      }

etc etc..


and the newPath function:

   newPath: function(oldPath){
      var i, newPath = '/logs/message_logs2/' + me.realm;
      
      for(i=25; i < oldPath.length; i++){
         newPath = newPath + oldPath[i]
         print(newPath);
      }
      return   newPath;
   },


any idea?

tyvm! :D

Top
 Profile  
 Post subject: Re: help with a script
PostPosted: Thu Apr 20, 2017 6:33 pm 
 
User
User

Joined: Mon Sep 12, 2011 3:49 am
You did not explain what your code is supposed to do, which makes it hard to help you. As such, i will just give you two examples of how your code behaves that i find odd, maybe that does the job:

if(me.profile.indexOf("_2") && path.indexOf("message_logs")){

indexOf returns the starting index of the first encountered match or -1 if none were found. Boolean(-1) === true. Therefore the function newPath is called whenever path does not begin with "_2" or "message_logs".

for(i=25; i < oldPath.length; i++){
         newPath = newPath + oldPath[i]
[...]

In case oldPath is long enough, you are adding a cropped part of oldPath to newPath which is quite weird:
newPath("\\test\\test\\test\\test\\testtesttest") === "/logs/message_logs2/europetesttest"

(apart from the question why you wouldn't simply do that, add the cropped part, instead of this weird for loop with magic numbers. Also noteworthy: "asia" does not have the same length as "europe", "useast" or "uswest" - i am assuming the stringlength of "/logs/message_logs2/"+me.realm is where your magic 25 comes from, in which case you should think of this - maybe a false assumption, '/logs/message_logs2/europe'.length === 26 afterall. It's the best explanation for the 25 i could find)

I would not at all be surprised if your function gave malformed, non-existant or inaccessible paths.

Top
 Profile  
 Post subject: Re: help with a script
PostPosted: Fri Apr 21, 2017 9:57 pm 
 
User
User

Joined: Wed Feb 04, 2015 12:17 am
@Hecate

thank u very much for ur reply, i will try to explain better.
Atm i got 8 chars doing baal runs, and i want to open 8 more. Sinceis im using files to communicate between chars, somehow i have to separate the files each br is using.

What i thought of doing is creating a new folder called "message_logs2" and direct all the second br's files there.
In order to do so i made all the 2nd br's profile name with "_2" ("leader_2", "leecher_2" etc etc)

then i wanted to change the path in Misc.fileaction function from "/log/message_logs/.." to "/log/message_logs2/.." - that's the purpose on function named "newPath".

if(me.profile.indexOf("_2") && path.indexOf("message_logs")){


the first condition is to make sure that newPath is applied only for profile names containing "_2".
second condition is to make sure the file is located in "message_logs" folder, and not something else.

for(i=25; i < oldPath.length; i++){
         newPath = newPath + oldPath[i]


to better understand my porpuse here, here is an example of a file i n to change the path to message_logs2
path = Misc.fileAction('/logs/message_logs/' + me.realm + ' DiabloLeader.txt', 0);

so somehow i need to add "2" after "..._logs"
U r right about the magic 25 :) - note that newPath = '/logs/message_logs2/' + me.realm, are 25 digits, so yeah - should be 26 in fact (idc about asia lol)
the purpose of the "for" loop is in order to add ' DiabloLeader.txt' to newPath

I hope i explained well enough

ty

Top
 Profile  
 Post subject: Re: help with a script
PostPosted: Fri Apr 21, 2017 11:50 pm 
 
User
User
User avatar

Joined: Thu Aug 04, 2005 1:12 am
Location: Australia
if(me.profile.indexOf("_2") && path.indexOf("message_logs"))


You're not checking the index, so even if it returns -1 (not containing) that if statement will always happen since as Hecate said, -1 === true.

I think I understand what you're trying to do, this is how I would do it, could make it more readable but meh:

if (me.profile.indexOf("_2") > -1 && path.indexOf("message_logs") > -1) {
  path = path.split("/").map(f => f.indexOf("message_logs") > -1 ? f + "2" : f).join("/");
}


this will change

'/logs/message_logs/useast/DiabloLeader.txt'


to this

'/logs/message_logs2/useast/DiabloLeader.txt'


Hope that helps.

Top
 Profile  
 Post subject: Re: help with a script
PostPosted: Sat Apr 22, 2017 11:26 am 
 
User
User

Joined: Wed Feb 04, 2015 12:17 am
@weiry6922

I have no idea what u wrote there, but it works

tnx alot! :)

Top
 Profile  
 Post subject: Re: help with a script
PostPosted: Sat May 20, 2017 6:45 pm 
 
User
User

Joined: Thu Dec 01, 2011 2:38 am
@weiry6922

I have no idea what u wrote there, but it works

tnx alot! :)



yea weiry is awesome , helped me so many times

Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests


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

Search for:
Jump to:  
cron