Results 1 to 10 of 10

Thread: setting variables

  1. #1
    Normal User
    Join Date
    Jul 2012
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    11
    Rep Power
    5

    setting variables

    Hi!

    Back in the days of ElfBot, it was possible to set variables (and use them anywhere) through the actions

    I am messing up with iBot but I am having no sucess so far


    Possible use:
    If a player attacks me, it sets a variable called "pk" from 0 to 1
    then an actions checks if this variable is 1, if true, gotolabel("x")
    then my toon finally reaches a safe zone, and in that stand point there is an action wpt that now checks if the variable is 1, if true, close tibia.

    My problem so far:
    The action "spams" its command, which means, it sends my character to label x even while I am in a really ahead waypoint,
    I tried to make the action change the variable value after it executed its command once, but, it is simply not doing it it (so after sendin its signal once, it would notice the variable 'PK' changed its value and thus wouldn't re-send its command)

    part of a code/small example of what I was trying:
    PHP Code:
    local pk 0

    if blahblah player attack and pk 0 then
      gotolabel
    ("x")
      
    pk 1
    end 
    Not sure if I described it the best way I could, I can reword it again if needed.
    Thanks beforehand!
    Last edited by Daewe; 07-12-2012 at 04:08 AM. Reason: typo

  2. #2
    Normal User ToadZ's Avatar
    Join Date
    Jul 2012
    Location
    Tarantula Caves - Tiquanda
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    26
    Rep Power
    5
    Create a action like this:

    Code:
    local pk = 0 
    
    if underattack("P") and pk == 0 then 
      gotolabel("x") 
      pk = 1 
    end
    And at label "x", use this:

    Code:
    if pk == 1 then
    setsettings("Settings\\Actions\\List\\MyToonAction\\Enable", "no")
    gotolabel("safeSpotPlease")  --you can use this if you like
    end
    PS: To compare variables values use "=="

  3. #3
    Normal User
    Join Date
    Jul 2012
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    11
    Rep Power
    5
    Is it just me or the actions(cavebot) doesn't check/understand values of variables that were made in the actions(persistent)?

  4. #4
    iBot User pink_panther's Avatar
    Join Date
    May 2012
    Location
    Australia
    Posts
    4,075
    Mentioned
    49 Post(s)
    Tagged
    1 Thread(s)
    Quoted
    178 Post(s)
    Reputation
    309
    Rep Power
    10
    Quote Originally Posted by Daewe View Post
    Is it just me or the actions(cavebot) doesn't check/understand values of variables that were made in the actions(persistent)?
    "pk" already exists its "playerattack"
    So... like what Toadz said...

    Make an action called "PlayerAttackCheck" that does:
    PHP Code:
    if playerattack then gotolabel("UnderAttack"end 
    Then in your Waypoints, have an Action labled "UnderAttack" that turns off the Player attack check with
    PHP Code:
    setsettings("Settings\\Actions\\List\\PlayerAttackCheck\\Enable""no"
    Failing to turn off the persistent script will cause it to keep running every 800 to 1000 ms and keep jumping to the waypoint, so it needs to be turned off once it has been triggered...

    Then under that waypoint, have the rest of the waypoints that run back to town and log out.

    Regarding your second question, it does, but defining it with "local" means it is only considered in that script... Global variables are defined in the setup and/or just say "j = 100" instead of "local j = 100"
    Last edited by pink_panther; 07-22-2012 at 11:49 PM.

  5. #5
    Normal User
    Join Date
    Jul 2012
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    11
    Rep Power
    5
    Oh, hi

    Yea, I already did all the stuff you said, my scrip is working wonderfully, but here comes the problem:

    Imagine that I had to setup a variable, in this case, P

    PHP Code:
    pk 0

    if underattack("P") and pk == 0 then 
      gotolabel
    ("x"
      
    pk 1
    end 
    It is on ACTIONS, you can see that pk should assume the value of 1, given that in this potential scenario, I got hit by a player
    So, you can also see that on the script 1st line there is "and pk == 0", but since its value already changed from 0 to 1, it shouldn't spam gotolabel('x')
    Thus, there wouldnt be a point in disabling the action since it would only command me gotolabel('x') once, ofc, later on my scripts/wpt, I would need to re-set the value of pk back to 0, but that is another story.

    The problem I encountered was: I couldn't make a action(CAVEBOT) to reset value of "pk" back to 0, hell, I couldn't even make the action(CAVEBOT) to check the value of PK.
    I.e, later on in the same script, I made a checker on a PZ to see if pk == 1, if so, it would closetibia() instead of going back to the cave, but it didn't work.

    I know the workaround of disabling the action, but, why wouldn't the potential scenario I described work in first place?

  6. #6
    Normal User wicholost's Avatar
    Join Date
    Jun 2012
    Location
    Jamaica, Chile
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    14
    Rep Power
    5
    PHP Code:
    local pkerlab 'x' -- label where the bot should go
    local pkerlabpos 
    = {x,y,z} -- position x y z of pkerlab

    if underattack("P"then  
        
    if posx ~= pkerlabpos[1] or posy ~= pkerlabpos[2] or posz ~= pkerlabpos[3then
            gotolabel
    (pkerlab)
        
    end
    end 

  7. #7
    Normal User
    Join Date
    Jul 2012
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    11
    Rep Power
    5
    Wouldn't that fail because it would repeat the gotolabel('x) after I move to the next wpt? since my posx/y/z would be different and thus repeat the process...

    But, still on the matter of setting variables, no further help?
    Because the pk example is just a small use of all the possible things I'd do with -working- variables

    Thanks for the help so far guys

  8. #8
    iBot User pink_panther's Avatar
    Join Date
    May 2012
    Location
    Australia
    Posts
    4,075
    Mentioned
    49 Post(s)
    Tagged
    1 Thread(s)
    Quoted
    178 Post(s)
    Reputation
    309
    Rep Power
    10
    Quote Originally Posted by Daewe View Post
    Oh, hi

    Yea, I already did all the stuff you said, my scrip is working wonderfully, but here comes the problem:

    Imagine that I had to setup a variable, in this case, P

    PHP Code:
    pk 0

    if underattack("P") and pk == 0 then 
      gotolabel
    ("x"
      
    pk 1
    end 
    It is on ACTIONS, you can see that pk should assume the value of 1, given that in this potential scenario, I got hit by a player
    So, you can also see that on the script 1st line there is "and pk == 0", but since its value already changed from 0 to 1, it shouldn't spam gotolabel('x')
    Thus, there wouldnt be a point in disabling the action since it would only command me gotolabel('x') once, ofc, later on my scripts/wpt, I would need to re-set the value of pk back to 0, but that is another story.

    The problem I encountered was: I couldn't make a action(CAVEBOT) to reset value of "pk" back to 0, hell, I couldn't even make the action(CAVEBOT) to check the value of PK.
    I.e, later on in the same script, I made a checker on a PZ to see if pk == 1, if so, it would closetibia() instead of going back to the cave, but it didn't work.

    I know the workaround of disabling the action, but, why wouldn't the potential scenario I described work in first place?
    if pk= 0 is in the same action script, it will run it every time, thus changing it back to 0 every time...

    so pk = 0, you get attacked, it changes to 1 then end.. then starts again, sets it to 0, ect...

  9. #9
    Normal User
    Join Date
    Jun 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    10
    Rep Power
    5
    try this:
    PHP Code:
    if not underattack('P'then pk 0 end

    if underattack('P') and pk == 0 then  
      gotolabel
    ('x')  
      
    pk 
    end 

  10. #10
    Normal User
    Join Date
    Jul 2012
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    11
    Rep Power
    5
    Quote Originally Posted by pink_panther View Post
    if pk= 0 is in the same action script, it will run it every time, thus changing it back to 0 every time...

    so pk = 0, you get attacked, it changes to 1 then end.. then starts again, sets it to 0, ect...
    I feel dumb for not recognizing that, now that you've mentioned it I brainstormed a new way to do it

    basically instead of setting values of 0 and 1, I will change make the script give -+ 1 to the current value, and if in the beggining of the script current value = value that means notu nderattack() (for this scenario) the script wont change it.

    Yay, you guys are aewsome =P

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •