Help with code

Need help running MacroQuest2? Ask your questions about how to get things to work on your computer.

Moderator: MacroQuest Developers

User avatar
Aarrow
a lesser mummy
a lesser mummy
Posts: 30
Joined: Thu Aug 12, 2004 2:38 pm

Help with code

Post by Aarrow » Thu Aug 12, 2004 3:01 pm

Can anyone help me with this code... kinda a noob, never really programed that much, etc. :?
What I'm trying to do is display if you're close enough to cast on something (If you are it will display 0, if not, it will display how much closer you need to be)

Code: Select all

${If[${Math.Calc[${Target.Distance}-${If[${Me.Gem[1].Range}==0,,${Me.Gem[1].Range}]}]}<=0,0,${Int[${Math.Calc[${Target.Distance}-${If[${Me.Gem[1].Range}==0,,${Me.Gem[1].Range}]}]}]}]}

Mimatas
a hill giant
a hill giant
Posts: 262
Joined: Wed Mar 10, 2004 4:22 pm

Post by Mimatas » Thu Aug 12, 2004 3:20 pm

Holy block code, batman.

When I run into trouble with incredibly nested code like this, I do a few things:

1. format it, so it's easy to see which parenthese, brackets, etc. line up.

2. Make sure that the types being returned are the types being expected by the function in which this function is nested.

3. break it up. Use multiple lines of code, rather than just nesting it all into one, and see if it works. This way, you can more easily narrow down WHY it doesn't work.

User avatar
Cr4zyb4rd
Plugins Czar
Posts: 1449
Joined: Tue Jul 20, 2004 11:46 am

Post by Cr4zyb4rd » Thu Aug 12, 2004 3:34 pm

Code: Select all

${If[${Math.Calc[${Target.Distance}-${Me.Gem[1].Range}]}>0,${Math.Calc[${Target.Distance}-${Me.Gem[1].Range}]},0]}

User avatar
Aarrow
a lesser mummy
a lesser mummy
Posts: 30
Joined: Thu Aug 12, 2004 2:38 pm

Post by Aarrow » Thu Aug 12, 2004 3:50 pm

Thanks Cr4zyb4rd.
I did almost the same thing right before I read your code, but wasn't sure if it was right or not...

Code: Select all

${If[${Math.Calc[${Target.Distance}-${Me.Gem[1].Range}]}<=0,0,${Math.Calc[${Target.Distance}-${Me.Gem[1].Range}]}]}
Going to test it now

User avatar
Aarrow
a lesser mummy
a lesser mummy
Posts: 30
Joined: Thu Aug 12, 2004 2:38 pm

Post by Aarrow » Thu Aug 12, 2004 3:58 pm

Works... Now the easy part, making it red if the target's out of range, yellow if it's in range, but out of sight, and green if it's inrange and I can cast on it. :smile:

fryfrog
a hill giant
a hill giant
Posts: 271
Joined: Fri Jun 20, 2003 5:37 am

Post by fryfrog » Thu Aug 12, 2004 4:11 pm

Is this going into a HUD or a UI? I think doing it in HUD is easy, but if you figure it out in UI please tell me :)

User avatar
Aarrow
a lesser mummy
a lesser mummy
Posts: 30
Joined: Thu Aug 12, 2004 2:38 pm

Post by Aarrow » Thu Aug 12, 2004 4:13 pm

UI, and sure I'll tell you how to do it.. When I'm done I'll post all the code (I'm using SOE's UI modded by SirCodeAlot). I'll probably post it there too...

Drumstix42
a grimling bloodguard
a grimling bloodguard
Posts: 808
Joined: Mon May 03, 2004 4:25 pm

Post by Drumstix42 » Thu Aug 12, 2004 5:23 pm

The reason they're asking is because the UI doesn't like like less than and greater than signs in the code. It things it's another XML tag, but it's not.

User avatar
Aarrow
a lesser mummy
a lesser mummy
Posts: 30
Joined: Thu Aug 12, 2004 2:38 pm

Post by Aarrow » Thu Aug 12, 2004 5:55 pm

Told you I'm a noob... Thanks a lot :smile:

No_Idea_At_All
a lesser mummy
a lesser mummy
Posts: 49
Joined: Sat Aug 07, 2004 11:28 pm

Post by No_Idea_At_All » Thu Aug 12, 2004 11:12 pm

Drumstix42 wrote:The reason they're asking is because the UI doesn't like like less than and greater than signs in the code. It things it's another XML tag, but it's not.
Actually I have not had a problem using the greater than sign, just the less than. So all your equations will have to take that into account.

Finally finished some graphics for my UI last night (and also fixed some errors) so hopefully when I get home I'll start posting it.

Although the distance thing is a good idea, I'll have to look into that :)

User avatar
Aarrow
a lesser mummy
a lesser mummy
Posts: 30
Joined: Thu Aug 12, 2004 2:38 pm

Post by Aarrow » Fri Aug 13, 2004 1:14 am

Well, I got it finished finally. Apparently SirCodeAlot is adding it into his next update... Anyway, here's the code

Code: Select all

	<Label item="MQ_Spell1A">
		<ScreenID>MQ_Spell1A</ScreenID>
		<EQType>9999</EQType>
		<Font>5</Font>
		<TooltipReference>${Int[${If[${Math.Calc[${Target.Distance}-${Me.Gem[1].Range}]}>0,${Math.Calc[${Target.Distance}-${Me.Gem[1].Range}]},]}]}</TooltipReference>
		<RelativePosition>true</RelativePosition>
		<Location>
			<X>95</X>
			<Y>12</Y>
		</Location>
		<Size>
			<CX>100</CX>
			<CY>20</CY>
		</Size>
		<Text>100</Text>
		<TextColor>
			<R>255</R>
			<G>0</G>
			<B>0</B>
		</TextColor>
		<NoWrap>true</NoWrap>
		<AlignCenter>false</AlignCenter>
		<AlignRight>false</AlignRight>
		<AlignLeft>true</AlignLeft>
	</Label>
	<Label item="MQ_Spell1B">
		<ScreenID>MQ_Spell1B</ScreenID>
		<EQType>9999</EQType>
		<Font>5</Font>
		<TooltipReference>${If[${Math.Calc[(${Target.Distance}-${Me.Gem[1].Range})*-1]}>0,${If[${Target.ID}==NULL,"",${If[${Target.LineOfSight}==FALSE,0,]}]},]}</TooltipReference>
		<RelativePosition>true</RelativePosition>
		<Location>
			<X>95</X>
			<Y>12</Y>
		</Location>
		<Size>
			<CX>100</CX>
			<CY>20</CY>
		</Size>
		<Text>100</Text>
		<TextColor>
			<R>255</R>
			<G>255</G>
			<B>0</B>
		</TextColor>
		<NoWrap>true</NoWrap>
		<AlignCenter>false</AlignCenter>
		<AlignRight>false</AlignRight>
		<AlignLeft>true</AlignLeft>
	</Label>
	<Label item="MQ_Spell1C">
		<ScreenID>MQ_Spell1C</ScreenID>
		<EQType>9999</EQType>
		<Font>5</Font>
		<TooltipReference>${If[${Math.Calc[(${Target.Distance}-${Me.Gem[1].Range})*-1]}>0,${If[${Target.ID}==NULL,"",${If[${Target.LineOfSight}==TRUE,"Cast",]}]},]}</TooltipReference>
		<RelativePosition>true</RelativePosition>
		<Location>
			<X>95</X>
			<Y>12</Y>
		</Location>
		<Size>
			<CX>100</CX>
			<CY>20</CY>
		</Size>
		<Text>100</Text>
		<TextColor>
			<R>0</R>
			<G>255</G>
			<B>0</B>
		</TextColor>
		<NoWrap>true</NoWrap>
		<AlignCenter>false</AlignCenter>
		<AlignRight>false</AlignRight>
		<AlignLeft>true</AlignLeft>
	</Label>
That's it.. PM me when you get your UI up No_Idea_At_All, I'd like to check it out.