How to combine text to object name?

Ask for help

Moderators: Murderator+, Murderator

Post Reply
Shokarta
Posts: 19
Joined: 2010-12-01 08:01:12

How to combine text to object name?

Post by Shokarta »

Hi guys, ive got this sorting maps script which works "teoreticaly" fine.
i THINK there is just problem on this part

Code: Select all

while i <= max
bag[i] = "maps_bag_"+str(i)

  while uo.getserial(bag[i]) <> "0x00000000"
as ive got MANY objects called maps_bag_NUMBER (NUMBER is variable of course)
so i need to use them somehow in the script and i thing when i use bag = "maps_bag_"+str(i) then it is concerned as a text, not as a object anymore...

any solution?



Code: Select all

sub maps()

uo.deletejournal()

VAR main_bag = "0x400C2379"

VAR i = 1
VAR max = 16

DIM bag[16] # must be same as VAR max

VAR journal,buffer,exit
VAR map,map_x,map_y

VAR journal_new,buffer_new,exit_new
VAR map_new,map_x_new,map_y_new

VAR search

# savebag
uo.print("Where to put maps?")
uo.addobject("maps_savebag")
while uo.targeting()
  wait(100)
wend


# bag 
while i <= max
  uo.addobject("maps_bag_"+str(i))
  while uo.targeting()
    wait(100)
  wend
  i = i + 1
wend


# mapa
uo.print("Choose one map")
uo.addobject("maps_catchmap")
while uo.targeting()
  wait(100)
wend

wait(500)

# zjisti pozici mapy
uo.useobject("maps_catchmap")
while NOT uo.injournal("Map opened to")
  wait(100)
wend

journal = uo.journal(uo.injournal('Map opened to')-1)
  
  # map_x
buffer = "" 
exit = 0
i=15 
while exit <> 1 
  if journal[i] <> ":" then 
    buffer = buffer + journal[i]
  else 
    exit = 1 
  endif 
  i = i + 1 
wend 
map_x = val(buffer) 

  # map_y
buffer = "" 
exit = 0
while exit <> 1 
  if journal[i] <> "" then 
    buffer = buffer + journal[i]
  else 
    exit = 1 
  endif 
  i = i + 1 
wend 
map_y = val(buffer) 

search = "Coordinates: "+str(map_x)+"x"+str(map_y)
uo.print(str(search))


i = 1

uo.deletejournal()

while i <= max
bag[i] = "maps_bag_"+str(i)

  while uo.getserial(bag[i]) <> "0x00000000"

    uo.moveitem(bag[i],1,"backpack")
    wait(500)
  
    repeat
    
      uo.findtype("0xFFFF","0xFFFF",bag[i])
      if uo.findcount() > 0 then
	uo.useobject("finditem")

	while NOT uo.injournal("Map opened to")
	  wait(100)
	wend

        journal_new = uo.journal(uo.injournal('Map opened to')-1)
  
        # map_x_new
        buffer_new = "" 
        exit_new = 0
        i=15 
        while exit_new <> 1 
          if journal_new[i] <> ":" then 
            buffer_new = buffer_new + journal_new[i]
          else 
            exit_new = 1 
          endif 
          i = i + 1 
        wend 
        map_x_new = val(buffer_new) 

          # map_y_new
        buffer_new = "" 
        exit_new = 0
        while exit_new <> 1 
          if journal_new[i] <> "" then 
            buffer_new = buffer_new + journal_new[i]
          else 
            exit_new = 1 
          endif 
          i = i + 1 
        wend 
        map_y_new = val(buffer_new)

        if ((((map_x - 30) <= (map_x_new)) AND ((map_x_new) <= (map_x + 30))) AND (((map_y - 30) <= (map_y_new)) AND ((map_y_new) <= (map_y + 30)))) then
          uo.moveitem("finditem",1,"maps_savebag")
	  wait(500)
        else
  	  uo.ignore("finditem")
          wait(1000)
	endif
      endif

    until uo.findcount() == 0
  
  wend
  i = i + 1
wend

end sub
Last edited by Shokarta on 2011-07-25 09:39:57, edited 1 time in total.
ZeroDX
Posts: 718
Joined: 2006-12-08 10:51:50
Location: Москва
Contact:

Re: How to combine text to object name?

Post by ZeroDX »

Try this

Code: Select all

while i <= max
bag[i] = "maps_bag_"+str(i)

  while uo.getserial(bag[i])
Shokarta
Posts: 19
Joined: 2010-12-01 08:01:12

Re: How to combine text to object name?

Post by Shokarta »

thanks works fine now....

well another issue is on row 148: Runtime error - Attempting to access array out of bounds (i marked the row in the script for you)

basicly it opens the map i choose, then it moves the first bag as it should, then it should open every map in the bag and by position it should work with the map... but it opens just one map, then the error occurs

which i dont understand why this error occurs, by my opinion it should would...
please have a look at that as im sure im just missing a detail :)

Code: Select all

sub mapy()

uo.deletejournal()

VAR main_bag = "0x400C2379"

VAR i = 1
VAR max = 16

DIM bag[16] # must be same as VAR max

VAR journal,buffer,exit
VAR map,map_x,map_y

VAR journal_new,buffer_new,exit_new
VAR map_new,map_x_new,map_y_new

VAR search

# savebag
uo.print("Where to put maps?")
uo.addobject("maps_savebag")
while uo.targeting()
  wait(100)
wend


# bag 
while i <= max
  uo.addobject("maps_bag_"+str(i))
  while uo.targeting()
    wait(100)
  wend
  i = i + 1
wend


# mapa
uo.print("Choose one map")
uo.addobject("maps_catchmap")
while uo.targeting()
  wait(100)
wend

wait(500)

# zjisti pozici mapy
uo.useobject("maps_catchmap")
while NOT uo.injournal("Map opened to")
  wait(100)
wend

journal = uo.journal(uo.injournal('Map opened to')-1)
  
  # map_x
buffer = "" 
exit = 0
i = 15 
while exit <> 1 
  if journal[i] <> ":" then 
    buffer = buffer + journal[i]
  else 
    exit = 1 
  endif 
  i = i + 1 
wend 
map_x = val(buffer) 

  # map_y
buffer = "" 
exit = 0
while exit <> 1 
  if journal[i] <> "" then 
    buffer = buffer + journal[i]
  else 
    exit = 1 
  endif 
  i = i + 1 
wend 
map_y = val(buffer) 

# search = "Coordinates: "+str(map_x)+"x"+str(map_y)
# uo.print(str(search))


i = 1

uo.deletejournal()

while i <= max
bag[i] = "maps_bag_"+str(i)

  while uo.getserial(bag[i])

    uo.moveitem(bag[i],1,"backpack")
    wait(500)
    uo.useobject(bag[i])
    wait(500)
  
    uo.findtype("0x14EB","0x0000",bag[i])

    while uo.findcount() > 0
    
      if uo.findcount() > 0 then
	uo.useobject("finditem")

	while NOT uo.injournal("Map opened to")
	  wait(100)
	wend

        journal_new = uo.journal(uo.injournal('Map opened to')-1)
  
        # map_x_new
        buffer_new = "" 
        exit_new = 0
        i = 15 
        while exit_new <> 1 
          if journal_new[i] <> ":" then 
            buffer_new = buffer_new + journal_new[i]
          else 
            exit_new = 1 
          endif 
          i = i + 1 
        wend 
        map_x_new = val(buffer_new) 

          # map_y_new
        buffer_new = "" 
        exit_new = 0
        while exit_new <> 1 
          if journal_new[i] <> "" then 
            buffer_new = buffer_new + journal_new[i]
          else 
            exit_new = 1 
          endif 
          i = i + 1 
        wend 
        map_y_new = val(buffer_new)

        if ((((map_x - 30) <= (map_x_new)) AND ((map_x_new) <= (map_x + 30))) AND (((map_y - 30) <= (map_y_new)) AND ((map_y_new) <= (map_y + 30)))) then
          uo.moveitem("finditem",1,"maps_savebag")
	  wait(500)
        else
  	  uo.ignore("finditem")
          wait(1000)
	endif

148:     uo.findtype("0x14EB","0x0000",bag[i])
      endif
  
    wend

  wend
  i = i + 1

wend

uo.moveitem("finditem",1,"maps_savebag")
uo.ignorereset()

end sub
ZeroDX
Posts: 718
Joined: 2006-12-08 10:51:50
Location: Москва
Contact:

Re: How to combine text to object name?

Post by ZeroDX »

Thats easy... Work with the journal, changing the value of i

Code: Select all

i = 15 
        while exit_new <> 1 
          if journal_new[i] <> ":" then 
            buffer_new = buffer_new + journal_new[i]
          else 
            exit_new = 1 
          endif 
          i = i + 1 
        wend 
        map_x_new = val(buffer_new) 

          # map_y_new
        buffer_new = "" 
        exit_new = 0
        while exit_new <> 1 
          if journal_new[i] <> "" then 
            buffer_new = buffer_new + journal_new[i]
          else 
            exit_new = 1 
          endif 
          i = i + 1 
        wend 
        map_y_new = val(buffer_new)
You need to define a new variable, which will work with bags only
Shokarta
Posts: 19
Joined: 2010-12-01 08:01:12

Re: How to combine text to object name?

Post by Shokarta »

thanks, how could i miss that im using VARIABLE i not only for bags but for the journal as well :)

script works fine, thanks man
Post Reply