Page 1 of 1

How to count 345+556

Posted: 2011-06-04 19:22:34
by Shokarta
Hey guys, on my shard we got a kind of jail (like a warning before they put you into real jail)
that you have to answer on a mtch questions for like 15 minutes....

question type:
<nick>: How much is 456 + 34?

and got to answer in 3s...

I dont know how to catch those two numbers into variables, so for now i have all that row from journal saved in variable ROW...

and now i need to separate those two numbers to work with that... could anybody help me please?

PS: each of those two numbers can have 1 (x), 2 (xx) or 3 (xxx) digits so i cant realy just set an exact position to cut part of the variable....

Re: How to count 345+556

Posted: 2011-06-04 20:38:14
by Scripts Writer
Interesting question if there could be more operators, than '+' (-, *, /).

Re: How to count 345+556

Posted: 2011-06-05 00:22:17
by ZeroDX
Парню бы помогли полезности с переведённым описанием)

Re: How to count 345+556

Posted: 2011-06-05 13:47:15
by Shokarta
so i have done some work which works up to half way

Code: Select all

sub karibik()

  var row
  var num1 = 0
  var num2 = 0
  var i = 0
  var multiply = 1

  uo.deletejournal()

  while NOT uo.injournal("How much is")
    wait(200)
  wend

  row = uo.journal(uo.injournal('How much is')-1)

  while NOT row[i] == "?"
    i = i + 1
  wend

  i = i - 1

repeat
#uo.print(row[i])
  num2 = num2 + (row[i] * multiply)
  i = i - 1
  multiply = multiply * 10
until row[i] == " "

end sub


the variable ROW is "<NICK>: How much is 345+556?"

so if i untag the row uo.print(row[i]) then injection will print into yournal this:
6
5
5

which is GOOD!

but this script has an error BAD OPERATION FOR THIS TYPE OF VARIABLE: NUM2 on row:
num2 = num2 + (row[i] * multiply)

if i try to put a INT() or VAL() in front of row[i] then the error is gonem but uo.print(int(row[i])) or uo.print(val(row[i])) does show NOTHING at all....

so please if anybodyu can correct me?

Re: How to count 345+556

Posted: 2011-06-05 15:38:02
by Scripts Writer
Well done, guy. U wrote nice start of script and i just correct this a little and finish. Now it's good calc ;)

Code: Select all

sub karibik()
  var row
  var result = 0
  var i = 0
  var multiply = 1
  uo.deletejournal()
  while NOT uo.injournal("How much is")
    wait(200)
  wend
  row = uo.journal(uo.injournal('How much is')-1)
  while NOT row[i] == "?"
    i = i + 1
    wait(100)
  wend
  i = i - 1
  repeat
    if row[i] <> '+' then
      result = result + (val(row[i]) * multiply)
      multiply = multiply * 10
    else
      multiply = 1
    endif
    wait(500)
    i = i - 1 
  until row[i] == " "
  uo.Print('Result :' + STR(result))
end sub


Image