/if statements on working

Help section from before the user variable changes that broke all macros

Moderator: MacroQuest Developers

Iceassassin
a lesser mummy
a lesser mummy
Posts: 49
Joined: Tue Nov 05, 2002 11:40 am

/if statements on working

Post by Iceassassin » Mon Jan 06, 2003 6:02 pm

Hmm.. My if statements don't work anymore.. Can anyone tell me whats wrong with this macro?

#include routines.mac

Sub Main
:loop
/call Heal

Sub Check
/if n $char(hp,pct)<100 /call Main
/if n $char(hp,pct)==100 /call End
/return

Sub Heal
/call check
/press 0
/delay 151
/goto :loop
/return

Sub End
/endmacro
/return

User avatar
SingleServing
a hill giant
a hill giant
Posts: 195
Joined: Tue Dec 17, 2002 11:00 pm

Re: /if statements on working

Post by SingleServing » Mon Jan 06, 2003 9:44 pm

Iceassassin wrote:Hmm.. My if statements don't work anymore.. Can anyone tell me whats wrong with this macro?

#include routines.mac

Sub Main
:loop
/call Heal

Sub Check
/if n $char(hp,pct)<100 /call Main
/if n $char(hp,pct)==100 /call End
/return

Sub Heal
/call check
/press 0
/delay 151
/goto :loop
/return

Sub End
/endmacro
/return
I don't think you can call main, never tried but it sounds totally wrong. You also never placed a /return in your main, try this

|*****************************************|

#include routines.mac

Sub Main
:Loop


/if n $char(hp,pct)<100 {

/press 0
/delay 151
/goto :Loop
}

/if n $char(hp,pct)==100 /return

|*****************************************|

I would use bbcodes for this macro but the < symbol is all fugered up
[color=DarkBlue]Everything,[/color] [color=DarkBlue][b]is[/b][/color] [color=black]black[/color] [color=DarkBlue]and[/color] [color=white]white[/color][color=DarkBlue], when you zoom out it looks[/color] [color=gray]grey[/color][color=DarkBlue].[/color]

Zorg
a lesser mummy
a lesser mummy
Posts: 44
Joined: Fri Oct 18, 2002 7:01 pm

Post by Zorg » Mon Jan 06, 2003 9:55 pm

Problem solved, not through SingleServing's smartass answer, but for some reason the board was displaying the codes for < and > instead of the characters themselves, and I failed to notice.
Last edited by Zorg on Mon Jan 06, 2003 10:48 pm, edited 1 time in total.

User avatar
SingleServing
a hill giant
a hill giant
Posts: 195
Joined: Tue Dec 17, 2002 11:00 pm

Post by SingleServing » Mon Jan 06, 2003 10:05 pm

Zorg wrote:I seem to be having a different problem related it if, /if "$foo(argument)"=="TRUE" will evaluate correctly, but /if $foo(argument)==TRUE doesn't.

The problem is, other people don't seem to be having the same problem. Scripts posted in the depot using the second style of /if are running for at least some people.
/if <n> <condition> <command>
Runs a command if the condition is true. (n makes the compare numeric)
Condition understands comparison operators

== Equal to
!= Not Equal to
> < Greater than; less than
>= <= Greater than or equal to; Lesser than or equal to
~~ contains operator (string only)

!~ does not contain operator (string only)
readme a lovely thing
[color=DarkBlue]Everything,[/color] [color=DarkBlue][b]is[/b][/color] [color=black]black[/color] [color=DarkBlue]and[/color] [color=white]white[/color][color=DarkBlue], when you zoom out it looks[/color] [color=gray]grey[/color][color=DarkBlue].[/color]

User avatar
Fippy
a snow griffon
a snow griffon
Posts: 499
Joined: Tue Jul 16, 2002 10:42 am

Post by Fippy » Tue Jan 07, 2003 4:44 am

Maybe you consider ss to be a smartarse but hes still correct /call Main is just plain wrong in many ways. So is a goto in a sub that goes into a different sub. It may well work for a while but its not easy to read and if you went on the write a 500 line script like that youd never be able to debug it.

/goto should only jump to a new place within the same sub

I realize your new to MQ scripting but flaming somebody for trying to help aint very nice. If you thinks somebody is an ass, ignore em.

this is the code you originally posted but editied to use proper flow control.


Sub Main
:loop
/call Heal
/if n $char(hp,pct)<100 /goto :loop
/return

Sub Heal
/press 0
/delay 151
/return



as you can see its a lot shorter and easier to understand.
Fippy

This is my girl. But Rizwank had her first :-)
[img]http://www.btinternet.com/~artanor/images/fairy_bounce09.gif[/img]

User avatar
SingleServing
a hill giant
a hill giant
Posts: 195
Joined: Tue Dec 17, 2002 11:00 pm

Post by SingleServing » Tue Jan 07, 2003 8:20 pm

Zorg wrote:Problem solved, not through SingleServing's smartass answer, but for some reason the board was displaying the codes for < and > instead of the characters themselves, and I failed to notice.
I am a smart ass but at least I have good intentions. I did try to help you and event wrote a working macro for you to use. My suggestions were ment to help you and not to mock you. I am sorry if I made you feel smaller, that was not my intention.

Yes < and > are messed up when you put them inside BBcode =/
[color=DarkBlue]Everything,[/color] [color=DarkBlue][b]is[/b][/color] [color=black]black[/color] [color=DarkBlue]and[/color] [color=white]white[/color][color=DarkBlue], when you zoom out it looks[/color] [color=gray]grey[/color][color=DarkBlue].[/color]

Malachi
a hill giant
a hill giant
Posts: 227
Joined: Tue Nov 19, 2002 1:29 am
Contact:

I know what it was.

Post by Malachi » Thu Jan 09, 2003 12:58 am

I know EXACTLY what the problem is.

It's a failure to use code brackets....hehe.

~malachi
~Oh danny boy, the pipes the pipes are calling.~

User avatar
SingleServing
a hill giant
a hill giant
Posts: 195
Joined: Tue Dec 17, 2002 11:00 pm

Re: I know what it was.

Post by SingleServing » Thu Jan 09, 2003 2:22 am

Malachi wrote:I know EXACTLY what the problem is.

It's a failure to use code brackets....hehe.

~malachi
No code brackets is what causes the problem

< and >

is the same as

Code: Select all

< and >
[color=DarkBlue]Everything,[/color] [color=DarkBlue][b]is[/b][/color] [color=black]black[/color] [color=DarkBlue]and[/color] [color=white]white[/color][color=DarkBlue], when you zoom out it looks[/color] [color=gray]grey[/color][color=DarkBlue].[/color]

AarynD
a lesser mummy
a lesser mummy
Posts: 45
Joined: Thu Jan 02, 2003 11:25 am

/call Main

Post by AarynD » Thu Jan 09, 2003 3:55 pm

Actually, /call Main is a legitimate construct in other programming languages (ie, functions meant to be called recursively)... It's doubtful MacroQest supports it. In either case, the call to main in the above code was not the proper use of a recursive call, as there is no "exit" back out of the recursion loop.

- Aaryn

User avatar
SingleServing
a hill giant
a hill giant
Posts: 195
Joined: Tue Dec 17, 2002 11:00 pm

Re: /call Main

Post by SingleServing » Thu Jan 09, 2003 4:53 pm

AarynD wrote:Actually, /call Main is a legitimate construct in other programming languages (ie, functions meant to be called recursively)... It's doubtful MacroQest supports it. In either case, the call to main in the above code was not the proper use of a recursive call, as there is no "exit" back out of the recursion loop.

- Aaryn
Key word "other" MQ is written in VC++ =)
[color=DarkBlue]Everything,[/color] [color=DarkBlue][b]is[/b][/color] [color=black]black[/color] [color=DarkBlue]and[/color] [color=white]white[/color][color=DarkBlue], when you zoom out it looks[/color] [color=gray]grey[/color][color=DarkBlue].[/color]

User avatar
Fippy
a snow griffon
a snow griffon
Posts: 499
Joined: Tue Jul 16, 2002 10:42 am

Post by Fippy » Fri Jan 10, 2003 3:55 am

Oh my somebody started talking about recursion. Before anybody starts asking what that is please lock this thread. it make me insane when people try to explain recursion to somebody with no knowledge of programming constructs.
Fippy

This is my girl. But Rizwank had her first :-)
[img]http://www.btinternet.com/~artanor/images/fairy_bounce09.gif[/img]

roguish
orc pawn
orc pawn
Posts: 29
Joined: Sun Jul 21, 2002 1:11 am

Post by roguish » Fri Jan 10, 2003 7:57 pm

recursion is when you call a routine, nothing works, you fix it you thought and your computer crashes, and you curse again and again