Jump to content

math_counter (Test Entity)


TylerH
 Share

Recommended Posts

I would like some people to look at and find some ways to test out my math_counter entity.

 

Attached Downloads section links are included to an improved base.lua file and the Counter.zip file archive. base.lua just has an added function entity:RelayMessage(message,delay,extra), which simply sends the message to all 8 targets of the entity that you call RelayMessage for.

 

ZIP:

http://leadwerks.com...ads&showfile=25

 

Base Lua:

http://leadwerks.com...ads&showfile=26

 

The Counter folder should be placed in SDK Root/Models/Entities/Math/.

 

(Idea/Icon/Names entirely stolen from Source Engine's Hammer -> math_counter on Source Engine Dev Wiki)

Here is a little write-up the entity, what it does, and how to use it:

 

Name: Math Counter

Icon:

Math_counter.png

Description: Stores a number (integer or floating point) value and manipulates it via Increments, Decrements, forced Set, Add, Subtract, Multiply, and Divide. It has a startvalue, which is what value will reset to if reset is true and it hits the max or min values.

Keys: Start Value, Value, Minimum Legal Value, Maximum Legal Value, Reset (Code friendly: startvalue, value, min, max, reset)

 

Receivable Messages:

  • add(number) - Adds the given number to the value. Triggers outvalue always and passes value as extra. Triggers onhitmin and/or onhitmax if the value is now >= max or <= min. Resets value to startvalue if reset is true.
  • subtracts(number) - Subtracts the given number from the value. Triggers outvalue always and passes value as extra. Triggers onhitmin and/or onhitmax if the value is now >= max or <= min. Resets value to startvalue if reset is true.
  • multiply(number) - Multiplies value by the given number. Triggers outvalue always and passes value as extra. Triggers onhitmin and/or onhitmax if the value is now >= max or <= min. Resets value to startvalue if reset is true.

  • divide(number) - Divides the value by the given number. NOTE: If number is 0, it is set to 1 to prevent divide by zero errors. Triggers outvalue always and passes value as extra. Triggers onhitmin and/or onhitmax if the value is now >= max or <= min. Resets value to startvalue if reset is true.
  • setvalue(number) - Sets the value to the given number. Triggers outvalue always and passes value as extra. Triggers onhitmin and/or onhitmax if the value is now >= max or <= min.
  • setvaluenofire(number) - Sets the value to the given number. Triggers no other events. Use this or directly set the entity key to set the value for future checks and operations.
  • setmin(number) - Sets the minimum legal value to the given number. Triggers no other events.
  • setmax(number) - Sets the maximum legal value to the given number. Triggers no other events.
  • getvalue - Sends the "ongetvalue" message to the entity that sent the "getvalue" message, and passes value. This is best used for entities that are not a target of the counter and need to know the counter's value, or for target's that want to circumvent "setvaluenofire"'s purpose.

Sent Messages:

  • onhitmax(self) - Sent when value is >= max. Passes the entity itself as extra.
  • onhitmin(self) - Sent when value is <= min. Passes the entity itself as extra.
  • outvalue(number) - Sent anytime the value is set (exceptions for entity key directly or via setvaluenofire). Passes the value as extra.
  • ongetvalue(number) - Sent to any entity that sends the counter the getvalue message. Passes the value as extra.

Please try this out!

 

Thanks,

Tyler

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

  • 2 weeks later...

I think this is a great idea. I haven't had a chance to test/use it though. I don't have a need for this just yet and working on a few other things. The only issue I have is the need for a custom base lua file. This isn't really your fault though as the way this was presented to us wasn't the best solution, but I think it's a big problem for distributing objects.

Link to comment
Share on other sites

You don't really need the custom base.lua file, you can just move the implementation of entity:RelayMessage into the math_counter.lua script itself.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Because I made the modified base.lua 3 days before I made math_counter, in an attempt to expand the base of the framework to support a Hammer-Like Input/Output system.

 

Ofcourse.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...