Author Topic: Is there a better way I can do this?  (Read 5235 times)

0 Members and 1 Guest are viewing this topic.

Offline JackCiaranTopic starter

  • Jr. Member
  • **
  • Posts: 35
  • Activity:
    0%
  • Reputation Power: 1
  • JackCiaran has no influence.
  • Respect: +2
  • Referrals: 1
    • View Profile
Is there a better way I can do this?
« on: April 04, 2010, 08:44:46 PM »
0
This actually works but I was wondering if there was something I can change to not path find my monster as much but still stay on it? or just even make it better! I get the message "Can't get there" when the monster dies.

SUB CHECKFORENEMIES
finditem abc g_10
if #findCnt > 0
{
set #lobjectid #findid
SET %q #findid
  event macro 27
  wait 5
  REPEAT
  finditem %q
   event pathfind #findx #findY
     event macro 27
     WAIT 5
until #findCNT = 0
GOSUB FINDCORPSE
}
GOSUB PRIMARYLOCATION
RETURN

« Last Edit: April 04, 2010, 09:37:35 PM by JackCiaran »

Scrripty

  • Guest
Re: Is there a better way I can do this?
« Reply #1 on: April 04, 2010, 10:57:57 PM »
0
If you look inside your sub here, you're doing a finditem for an enemy right?  Then if you FIND the enemy, you're executing whatever is in the brackets.  What JAF said is that when your enemy DIES you don't FIND him anymore... so you're not executing anything in the brackets... hence you're not FINDING THE CORPSE FOR LOOTING. hehe  Cause it's in the brackets where you find the monster... and he's dead... so you can't find him anymore... :)

Code: [Select]
SUB CHECKFORENEMIES
finditem abc g_10
if #findCnt > 0
{
set #lobjectid #findid
SET %q #findid
  event macro 27
  wait 5
  REPEAT
  finditem %q
   event pathfind #findx #findY
     event macro 27
     WAIT 5
until #findCNT = 0
GOSUB FINDCORPSE
}
GOSUB PRIMARYLOCATION
RETURN
« Last Edit: April 05, 2010, 11:48:39 AM by Scripty »

Offline JackCiaranTopic starter

  • Jr. Member
  • **
  • Posts: 35
  • Activity:
    0%
  • Reputation Power: 1
  • JackCiaran has no influence.
  • Respect: +2
  • Referrals: 1
    • View Profile
Re: Is there a better way I can do this?
« Reply #2 on: April 05, 2010, 10:52:21 AM »
0
thankyou Twinkle McNugget could someone help me learn how to use the brackets in this situation? I basically dont understand the proper way to use them and can't find a reference to go from that I can understand.

Offline JackCiaranTopic starter

  • Jr. Member
  • **
  • Posts: 35
  • Activity:
    0%
  • Reputation Power: 1
  • JackCiaran has no influence.
  • Respect: +2
  • Referrals: 1
    • View Profile
Re: Is there a better way I can do this?
« Reply #3 on: April 05, 2010, 11:26:10 AM »
0
alright what i am trying to get the sub to do is
find the enemy
if I find one (if I dont find any monsters I wanna go to my sub primarylocation)
check to see if the monster is >= 2 tiles away
if it is
pathfind to it
wait ( to give it time to get there )
attack the monster
and then I want to check to see if the monster is >= 2 tiles away
and if it is
pathfind to it again ( because i believe the findx and findy will change from the original find if the monster moves and ill go to the wrong spot so i would like to check it again)
and then i want to wait for the monster to die ( the way i found to do that was with #findCNT = 0 )
after its dead i want to go to my sub find corpse.

now after typing this out would it be best to just make another sub instead of trying fit all that into one sub?


Offline JustAnotherFace

  • Hero Member
  • *
  • Posts: 530
  • Activity:
    0%
  • Reputation Power: 8
  • JustAnotherFace has no influence.
  • Gender: Male
  • My new toy....
  • Respect: +24
  • Referrals: 4
    • View Profile
Re: Is there a better way I can do this?
« Reply #4 on: April 05, 2010, 11:38:54 AM »
0
thankyou Twinkle McNugget could someone help me learn how to use the brackets in this situation? I basically dont understand the proper way to use them and can't find a reference to go from that I can understand.

To help answer your question, lets take a look at your code.



Code: [Select]
SUB CHECKFORENEMIES
finditem abc g_10
if #findCnt > 0
{
set #lobjectid #findid
SET %q #findid
  event macro 27
  wait 5
  REPEAT
  finditem %q
   event pathfind #findx #findY
     event macro 27
     WAIT 5
until #findCNT = 0
GOSUB FINDCORPSE
}
GOSUB PRIMARYLOCATION
RETURN

Now, in this code below, you are telling your script to find something and then saying IF it finds abc to do EVERYTHING inside of the code tags that follow:

Code: [Select]
SUB CHECKFORENEMIES
finditem abc g_10
if #findCnt > 0

So, lets say the script finds abc on the ground within 10 tiles.  The script then knows to execute the code within the code tags that follow:


Code: [Select]
{
set #lobjectid #findid
SET %q #findid
  event macro 27
  wait 5
  REPEAT
  finditem %q
   event pathfind #findx #findY
     event macro 27
     WAIT 5
until #findCNT = 0
GOSUB FINDCORPSE
}

Once your script jumps into the code brackets you have it repeating the finditem %q (your monster) AND pathfinding to %q's coordinates until the findcnt = 0, at which point it jumps out of the repeat and goes to the sub Findcorpse.  When your Sub Findcorpse completely executes, it should return you back to the line following your gosub findcorpse statement.... which just happens to be your } bracket.  The script then sees that the code bracket has been closed and executes the next line of code.

Now, the difference is this... When the script does the Finditem abc g_10 and executes the IF #findcnt > 0 and it finds NOTHING the script knows NOT to jump into the brackets and execute the code inside of them.  Which means, it jumps straight past the brackets down to the GOSUB PRIMARYLOCATION line and executes it.

I hope this helps to answer your question.

JaF



All that tyranny needs to gain a foothold is for people of good conscience to remain silent.
Thomas Jefferson

Scrripty

  • Guest
Re: Is there a better way I can do this?
« Reply #5 on: April 05, 2010, 11:41:03 AM »
0
thankyou Twinkle McNugget could someone help me learn how to use the brackets in this situation? I basically dont understand the proper way to use them and can't find a reference to go from that I can understand.

Brackets are only used in certain situations.  With if's if they are greater than one line AFTER the if statment is one.

The example below is correct because it only has one line AFTER the if.  If that statement were #TRUE, it would execute the next line by setting %Jack to whatever.  If it were #FALSE, it would read the IF statement, see it's #FALSE, and SKIP the next line without brackets and execute the very next line after the SET command.

Code: [Select]
IF %Jack = noob
  SET %Jack Is_having_trouble_with_brackets

This next example has MORE than 2 lines after IF statement.  So you MUST use brackets to execute it all together as part of the IF #TRUE/#FALSE, or it will not be correct.  Example:  

Code: [Select]
IF %Jack = noob
{
  SET %Jack Is_having_trouble_with_brackets
  SET %Jack1 He_is_learning_tho
}

The above is correct, and ONLY those 2 lines in the bracket will be executed if the IF is #TRUE.  If it's #FALSE, it would skip those 2 lines in the brackets.  It's really easy when you get the hang of it.  90 percent of your problems right now while you're learning will be syntax problems.  Just keep at it and you'll get it. :)  Also:  You need to use brackets with whiles and repeats and fors also... there's probly more but I'm wingin it.
« Last Edit: April 05, 2010, 11:43:48 AM by Scripty »

Offline Paulonius

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +162
  • Referrals: 1
    • View Profile
Re: Is there a better way I can do this?
« Reply #6 on: April 05, 2010, 11:45:35 AM »
0
To complicate it just a bit more, you can tell the If conditional how many lines to execute if the condition is met in lieu of using brackets by using a number at the end of the conditional line:

Code: [Select]
If %Twinkle McNugget = Helpful 2
     Thank him
     Give him some SUO Karma love by hitting the heart under his icon

will run the same as:

Code: [Select]
If %Twinkle McNugget = Helpful
     {
     Thank him
     Give him some SUO Karma love by hitting the heart under his icon
     }

I prefer the brackets because I will inevitably screw up more otherwise, but its helpful to know its an option when you read other folks' scripts as some of them use the number convention.

This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

Offline JustAnotherFace

  • Hero Member
  • *
  • Posts: 530
  • Activity:
    0%
  • Reputation Power: 8
  • JustAnotherFace has no influence.
  • Gender: Male
  • My new toy....
  • Respect: +24
  • Referrals: 4
    • View Profile
Re: Is there a better way I can do this?
« Reply #7 on: April 05, 2010, 11:48:33 AM »
0
I also prefer the brackets because I think it makes the code easier to follow.  Just a personal preferance I suppose, as either way will function the same.
All that tyranny needs to gain a foothold is for people of good conscience to remain silent.
Thomas Jefferson

Scrripty

  • Guest
Re: Is there a better way I can do this?
« Reply #8 on: April 05, 2010, 11:52:37 AM »
0
To complicate it just a bit more, you can tell the If conditional how many lines to execute if the condition is met in lieu of using brackets by using a number at the end of the conditional line:

Paul have you actually tried writing a script like this?  I tried it and in some instances it didn't execute as I would have expected.  I eventually ripped it all out and did it right. :)  It DOES work, but I believe there are instances where it doesn't.  While you're learning Jack, don't use this.  It's more of an advanced thing even tho it's easy. :)

Offline Paulonius

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +162
  • Referrals: 1
    • View Profile
Re: Is there a better way I can do this?
« Reply #9 on: April 05, 2010, 12:01:03 PM »
0
I don't use it, so no, I have not written any code using it, but its in a bunch of scripts.  Snicker7 has it in the bodfiller that I was just digging through... I only mentioned it so that Jack would know what he was looking at if he runs into it.
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

Offline JackCiaranTopic starter

  • Jr. Member
  • **
  • Posts: 35
  • Activity:
    0%
  • Reputation Power: 1
  • JackCiaran has no influence.
  • Respect: +2
  • Referrals: 1
    • View Profile
Re: Is there a better way I can do this?
« Reply #10 on: April 05, 2010, 03:45:35 PM »
0
Thanks everyone for your input it made my script change completely haha but I feel its tons better!
I am curious tho is there a way to set a pathfind location onto something like this
set %first_location_of_where_I_want_to_go  8745 81
and then use
event pathfind %first_location_of_where_I_want_to_go
to call on it? or am I using the wrong code for that

Offline JustAnotherFace

  • Hero Member
  • *
  • Posts: 530
  • Activity:
    0%
  • Reputation Power: 8
  • JustAnotherFace has no influence.
  • Gender: Male
  • My new toy....
  • Respect: +24
  • Referrals: 4
    • View Profile
Re: Is there a better way I can do this?
« Reply #11 on: April 05, 2010, 03:53:33 PM »
0
Thanks everyone for your input it made my script change completely haha but I feel its tons better!
I am curious tho is there a way to set a pathfind location onto something like this
set %first_location_of_where_I_want_to_go  8745 81
and then use
event pathfind %first_location_of_where_I_want_to_go
to call on it? or am I using the wrong code for that

Try this...

Set %X 8745
Set %Y  81
Event Pathfind %X %Y
All that tyranny needs to gain a foothold is for people of good conscience to remain silent.
Thomas Jefferson

Scrripty

  • Guest
Re: Is there a better way I can do this?
« Reply #12 on: April 05, 2010, 03:53:44 PM »
0
Yes, you can even number them like this:  locationx1 location y1 location x2 location y2... and so on... and then call them with a loop to have your character walk a path... :)

Tags: