• Print

Author Topic: Always round numbers  (Read 10289 times)

0 Members and 1 Guest are viewing this topic.

Offline Reese

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Always round numbers
« on: May 23, 2016, 10:19:53 am »
Hello guys,
I would like to know if ULib.cmds.NumArg could be 0.5 (like not rounded)
Here's the code :

cmd = ULib.cmds.TranslateCommand( "ugm slap", ULib.slap )
cmd:addParam{ type=ULib.cmds.PlayerArg, target="*", default="^", ULib.cmds.optional }
cmd:addParam{ type=ULib.cmds.NumArg, min=0, default=0, ULib.cmds.optional }

It is always 0 for 0.4 and always 1 for 0.5 !
Thank you guys

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Always round numbers
« Reply #1 on: May 23, 2016, 10:26:50 am »
From the docs, it doesn't look like it usually rounds. Maybe this is a bug?
Can you try your command with 1.5? Or anything >1?
Maybe also try .5 instead of 0.5? I would doubt that's the issue, but I don't know.
bw81@ulysses-forums ~ % whoami
Homepage

Offline Reese

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: Always round numbers
« Reply #2 on: May 23, 2016, 10:51:35 am »
Still rounds up man

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Always round numbers
« Reply #3 on: May 23, 2016, 01:12:24 pm »
I will need to double check, but it should not be rounding. Are you rounding in the destination function?
Experiencing God's grace one day at a time.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Always round numbers
« Reply #4 on: May 23, 2016, 01:16:12 pm »
Wait, I just noticed. OP, that code doesn't look like code you'd be using to write a command of your own. If it is, that doesn't look correct.
Please post the entirety of the code you're using to test using [code=lua][/code] to surround it.

Also, Meg, it doesn't seem to unless it's cut off before parsing: https://github.com/TeamUlysses/ulib/blob/master/lua/ulib/shared/commands.lua#L254
« Last Edit: May 23, 2016, 01:21:15 pm by Bytewave »
bw81@ulysses-forums ~ % whoami
Homepage

Offline Reese

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: Always round numbers
« Reply #5 on: May 27, 2016, 03:13:00 pm »
I just took an exemple code but I did the same kind of code

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Always round numbers
« Reply #6 on: May 27, 2016, 03:31:11 pm »
I just took an exemple code but I did the same kind of code
Could you post your code as I suggested? It would really help us in figuring out what your issue is. Thanks.
bw81@ulysses-forums ~ % whoami
Homepage

Offline Reese

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: Always round numbers
« Reply #7 on: May 28, 2016, 01:33:07 am »
Thank you
« Last Edit: May 28, 2016, 02:16:25 pm by Reese »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Always round numbers
« Reply #8 on: May 28, 2016, 09:20:56 am »
Have you tried printing the scale variable to verify that it is being rounded?
Experiencing God's grace one day at a time.

Offline Reese

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: Always round numbers
« Reply #9 on: May 28, 2016, 09:37:36 am »
what do you mean ? I may be not understnading everything

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Always round numbers
« Reply #10 on: May 28, 2016, 09:52:04 am »
what do you mean ? I may be not understnading everything
Code: Lua
  1. function ulx.scale( calling_ply, target_plys, scale )
  2.     print(scale)
  3.     -- your code goes here
bw81@ulysses-forums ~ % whoami
Homepage

Offline Reese

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: Always round numbers
« Reply #11 on: May 28, 2016, 10:04:29 am »
0.5
ServerLog: [ULX]**** set the scale for Themself to 0
You set the scale for Yourself to 0

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Always round numbers
« Reply #12 on: May 28, 2016, 10:42:53 am »
Mhmm... The scale variable actually holds a decimal number (0.5) but it's being displayed as a whole number (0).

Have a look at the line of code that is responsible for displaying that message:
Code: Lua
  1. ulx.fancyLogAdmin( calling_ply, "#A set the scale for #T to #i", target_plys, scale )
You're telling ulx.fancyLogAdmin to display scale as an integer (#i). It's doing what you ask it to. :)

Try these instead:
#f - Display a floating point number with 6 digits after the point (10.129 is displayed as 10.129000).
#.2f - Display a floating point number with 2 digits after the point (10.129 is displayed as 10.13).
#g - Display a floating point number using the shortest possible representation (10.129 is displayed as 10.129).

There are lots of ways to format numbers! I used http://www.cplusplus.com/reference/cstdio/printf/ as a reference.
« Last Edit: May 28, 2016, 02:06:45 pm by Timmy »

Offline Reese

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: Always round numbers
« Reply #13 on: May 28, 2016, 01:07:54 pm »
So it only what is displayed that is rounded

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Always round numbers
« Reply #14 on: May 28, 2016, 01:20:26 pm »
Yes
Experiencing God's grace one day at a time.

  • Print