Skip to content

Beginner's Nexus Question

edited August 2018 in Scripting
I'm learning scripting here with a fishing script.  At the moment there is one issue I can't seem to understand or work around.

I have an alias, FISHTO <fishing_dir> that sets a variable @fishing_dir to <fishing_dir> and then casts the pole @fishing_dir.  So far, so good.

Next, I have a trigger that automatically reels (if necessary), baits the pole and recasts every time I probe it and see there is no bait.  The issue appears when I get to the CAST command: the @fishing_dir is being magickally cleared immediately after my first "CAST" in the FISHTO alias.  Can anyone explain why?

Best Answers

  • OhmOhm
    Accepted Answer
    If you are not saving the variable <fishing_dir> in a new global variable, then you cannot use it outside of the alias FISHTO. The solution is to store the variable <fishing_dir> in a new global variable and then invoke it as and when required.
    image
  • OhmOhm
    Accepted Answer
    try @set fish_dir @fishing_dir
    image

Answers

  • Thank you, Ohm!  How do I know that it is saved as a global variable?  At the moment I am just using the simplified scripting UI that Nexus provides in the "settings" window.  I can look see the <fishing_dir> variable listed in the "Variable" tab, but it's content is just set to <fishing_dir>, which shows up as blank.
  • Yes it took me some time to store variables into global variables 

    it usually works with the keyword ‘set’ as a regular command
    image
  • A variant on this worked.  I used the fact that additions to an alias get at the end of the command, and just set it to: @set @fishing_dir.  Thanks for all the help!  Time to move in the next problem. ;)
  • TIme for the next question already... are the IF statements broken?  I'm still using Nexus' simplified scripting interface.  For the life of me, I can't get a variable with a number stored in it to register as true when compared to the same number.
      For example:  IF @have_fish IS = 1 then REEL otherwise POUT.  

    I have tried writing everything in quotes, to force it to strings;  I've checked for extra spaces where they shouldn't be;  Switched IS to ISNOT, just to confirm; tried a greater than approach; tried switching my then/otherwise;  and done basically anything I could think of, regardless of whether it made sense or not.  I've verified in the Variables tab and with SAY commands in the middle of the script that the variable is actually registering the change, but I can't get the IF statement to ever acknowledge that 1 IS = 1.
  • edited September 2018
    if/then statements typically are true/false like:
    if foo = true then say foo is true! 
    end
    'otherwise' is elseif. which in my limited (limited) coding experience usually means you need another true/false statement which means you'd be looking at:

    if foo= true then say foo is true!
    elseif foo= false then pout.
    end
    I'm aware there's likely another way, I think (again, limited experience here) using 'not true' to make it so if it comes up as anything other than true it does the elseif statement.

    But I don't know how Nexus works as I don't use it myself, but it seems to operate on similar rules as Lua.
  • TIme for the next question already... are the IF statements broken?  I'm still using Nexus' simplified scripting interface.  For the life of me, I can't get a variable with a number stored in it to register as true when compared to the same number.
      For example:  IF @have_fish IS = 1 then REEL otherwise POUT.  

    I have tried writing everything in quotes, to force it to strings;  I've checked for extra spaces where they shouldn't be;  Switched IS to ISNOT, just to confirm; tried a greater than approach; tried switching my then/otherwise;  and done basically anything I could think of, regardless of whether it made sense or not.  I've verified in the Variables tab and with SAY commands in the middle of the script that the variable is actually registering the change, but I can't get the IF statement to ever acknowledge that 1 IS = 1.
    I was trying to get variables to resolve in the if statements, and ended up moving to advanced scripting cause I couldn't figure it out.
  • It works quite well actually. 

    You use the If statement

    You use the Variable @have_Fish
    You use the comparison is and =
    You use the Value 1

    You use the qualifier - Keep going for condition 1
    You use the qualifier - Stop for condition anything else.

    You also have to have the right trigger or alias to trigger the comparison of the variable value.


    image
  • edited September 2018
    Ohm said:
    It works quite well actually. 

    You use the If statement

    You use the Variable @have_Fish
    You use the comparison is and =
    You use the Value 1

    You use the qualifier - Keep going for condition 1
    You use the qualifier - Stop for condition anything else.

    You also have to have the right trigger or alias to trigger the comparison of the variable value.



      @Ohm : That is, as far as I can tell, exactly what I've been trying to do.  Here is a screenshot of the logic and a log, to show how it is working.  https://www.dropbox.com/sh/c04csouryspp8gz/AABd-hWNCUXN-MrgYe_VCf2ia?dl=0

    Basically, for the purposes of testing I created an endless loop scenario to see if it would ever switch from Then to Otherwise or vice versa.  All of the logic is shown the the screencap except for the trigger "Line goes taut", which is working just fine.  If the IF block evaluates true it is supposed to reel, and if false then it displays a message stating the @have_fish variable before looping back to reel again.  There are other triggers that can change the @have_fish to equal 0, evidence of these at work is shown in the log as well.  As the log shows, it always evaluates false, even when set to what should be true.

    Like I stated above, I've tryed forcing everything to strings; checking the match case box;  flipping various options around;  at the end of the day, I simply cannot figure out how to get the IF statement to identify the value 1 with the 1 assigned to the variable.
  • Your issue is you are comparing a value to a value. Change the first value in the IF statement to a variable. 

    Right now you are comparing one value  to another which will never be true
    image
  • edited September 2018
    Ohm said:
    Your issue is you are comparing a value to a value. Change the first value in the IF statement to a variable. 

    Right now you are comparing one value  to another which will never be true
    HUZZAH!!!! I don't know how I missed this, but I made the same mistake in every IF block in my scripting.  I first suspected that the solution may have been a combination of this observation and Jeremy's recommendation to remove the @ prefacing the variable name in the IF block, but now I'm wondering if it may have just been this.  In any case: Thank you!!!
Sign In or Register to comment.