[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Python
. . -> [Subject]  Converting a VBscript plugin

Converting a VBscript plugin

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Rakon   USA  (123 posts)  [Biography] bio
Date Thu 21 Dec 2006 08:27 AM (UTC)
Message
Greetings. Currently Im running a MUD 'system' in python, for an IRE game. Though I really like python and am more famlier with its language, I've been trying to get a VBscript plugin written for python, integrated into my script, using python.

I don't really know how to go about doing the correct functions in Python, though it works fine in the plugin.

The question is, anyone able to help me convert the following plugin into a Python state, or give me an idea on how to go about writing the functions for it to work??

The plugin: http://www.gammon.com.au/mushclient/plugins/Health_Bar.xml

Thanks
-Rakon

Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for.
[Go to top] top

Posted by Nick Gammon   Australia  (22,966 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Fri 22 Dec 2006 03:10 AM (UTC)
Message
I'm not sure what the problem is. The main difference would be simply syntactic differences, which you should be able to do easily enough if you are familiar with Python (which I am not). Can you post an example of what you are attempting, and in what way it doesn't work?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Rakon   USA  (123 posts)  [Biography] bio
Date Reply #2 on Thu 04 Jan 2007 01:17 PM (UTC)
Message
Hello again.

The issue is, while I have converted the plugin to python, using the syntax's I believe to be correct in what I desire for it to do. (Behave the same way as ked's plugin, in VB).

It(his) performs the basic math, and allocates a number in assigning how many 'g's to place like a bar. It is able to have half the 'g's of ten, one colour, and the rest another, depending on the math's count.

When I do this SAME thing in python, it doesn't change part of the total of 'g's to another colour, it either has them all one colour, all the other defined colour, or not showing at all (black).

Ked's(VBscript)

sub DoGauge (sPrompt, iCurrent, iMax, sGoodColour, sBadColour)
dim pc, count

'
'  Do prompt in black Arial
'
  InfoColour "black"
  InfoFont "Arial", 10, 0
  Info sPrompt

'
'  Use Webdings for gauge (black square)
'

  InfoFont "Webdings", 10, 0

  pc = CInt ((CInt (iCurrent) / CInt (iMax)) * 10)

'
'  Below 20% warn by using different colour
'

  if pc < 3 then
    InfoColour sBadColour
  else
    InfoColour sGoodColour
  end if 
 
'
'  Draw active part of gauge
'
  if pc < 1 then
	InfoColour "black"
  end if 
  for count = 0 to pc
    Info "g"
  next  

'
'  Draw rest of gauge in grey (ie. unfilled bit)
'

  InfoColour "dimgray"
  while count <= 10
    count = count + 1
    Info "g"
  wend

end sub


Mine(Python):

def DoGauge(Prompt, Current, Max, HColour, LColour):
	world.InfoColour("Orange")
	world.InfoFont("Arial", 10, 0)
	world.Info(Prompt)
	
	world.InfoFont("Webdings", 10, 0)
	count = int(Current) / int(Max) * 12

	

	if count < 4:
		world.InfoColour(LColour)
	else:
		world.InfoColour(HColour)
	

		
	for i in range(0,count):
		world.Info("g")
		
	while count <= 11:
		world.InfoColour("dimgrey")
		count += 1
		world.Info("g")		


As you can see, it essentially the same, just different syntax's. What I am confused to is WHY my version only colours them all, or not at all. While HIS will change a few based off the math. Any ideas??

Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #3 on Thu 04 Jan 2007 08:58 PM (UTC)
Message
Well, yours multiplies by 12 instead of his 10; is that intentional? You also use "dimgrey" instead of his "dimgray". Finally, you do not convert the result of the division to an integer; I don't know if Python distinguishes between a number and an integer. It's possible that the int function returns the floored version, not an actual integer that behaves like integers with respect to division etc. I'd apply int to the result of the division and see what happens.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Nick Gammon   Australia  (22,966 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sat 06 Jan 2007 04:00 AM (UTC)
Message
Quote:

You also use "dimgrey" instead of his "dimgray".


InfoColour does nothing if not given a valid colour name, so this may well be your problem.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Rakon   USA  (123 posts)  [Biography] bio
Date Reply #5 on Sat 06 Jan 2007 11:24 AM (UTC)

Amended on Sat 06 Jan 2007 12:47 PM (UTC) by Rakon

Message
The InfoColour is still not the problem, though thanks for pointing it out. Simple logic 'spelling > me'.

The '12' I have for the count is just because I want two extra blocks, 'g's to show up.

However even now, when I have only changed the value, 'dimgrey' to 'dimgray', I'm still having the same issue.

**EDIT** RTFM before commenting something doesn't work.

In python:

count = round(round(Current) / round(Max) * 12)


Is the equiv of the VB:

pc = CInt ((CInt (iCurrent) / CInt (iMax)) * 12)


The CInt function rounds to a nearest 'even' number, where as Int would just change the value to be an integer.
Thanks for the help.
--Rakon

Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #6 on Sun 07 Jan 2007 02:02 AM (UTC)
Message
Actually I don't think that round and cint do the same thing. cint truncates a number, that is, takes the floor. 3.9 becomes 3. round, well, rounds the number. By 'even' did you mean whole or really even as in the opposite of odd?

In any case I'm glad that was the problem. You were converting only part of the expression, and as I said in my earlier post you really want to do the whole thing to get the values you need.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Isthiriel   (113 posts)  [Biography] bio
Date Reply #7 on Fri 19 Jan 2007 11:05 AM (UTC)
Message
Python has an integer division operator "/" and a float division operator "/". Do not confuse the two.


    count = 12 * int(Current) / int(Max)


Should achieve what you are looking for... though personally I'd roll with:


    count = int(12.0 * Current / Max)


As I recollect it, the / (and * &c..) are left-associative and the result is of the same type as the left operand (the right operand is cast to the correct type before the operator function is called). So in this case int(Current) / int(Max) gives you 0 which is then multiplied by 12 and amply explains why the bar is completely grey.
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


23,988 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]