Numberfields does not work? (Float expected)

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Numberfields does not work? (Float expected)

Post by XASSASSINX »

I made a simple slider for my mod (or rather, remake of a mod), but after making everything, using this slider with decimals points breaks some of the values, showing VERY broken numbers on the print function.

After reading on the Wiki, number fields seems to be the best option, working as a slider with set jumps, but it doesn't matter how i put it, it NEVER works. Is there a mod or a sample on how it should look like?

Code: Select all

	NumberField "Multiply the amount of scrap required to upgrade.", "cl_ScrapMultiplier", [, 0.25, 2.5 [, 0.25 [, "0" ]]]]	
Here is a random sample of mine. With or without the "check" it doesn't work.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Numberfields does not work? (Float expected)

Post by Jarewill »

The [] brackets are not meant to be copied. On the wiki they mean "optional argument".
I also think that "check" should be checking for another bool CVar, or be just skipped.
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Numberfields does not work? (Float expected)

Post by XASSASSINX »

Well, that is misleading. I thougt the brackets were necessary. So i just put in the numbers of the field?

Also, it seems to be jumping 1 value at a time, as in, literal jumping from 0 to 1 to 2. I know that inc defines the amount of value to jump, but it doesn't seem to be working.

Code: Select all

	NumberField "Multiply the amount of scrap required to upgrade.", "cl_ScrapMultiplier", 0.25, 2.5, 0.25 	
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Numberfields does not work? (Float expected)

Post by Jarewill »

This looks off to me too. I don't really see a reason why it wouldn't jump every 0.25 units, as it jumps normally with a value like 2.
However, the slider works right with this. The reason why decimal numbers break the ACS print function from the previous thread, is because it uses f:90.
After checking in the console, setting a float CVar with a decimal number, sets it as just "1" or "2" and not "1.0" / "2.0".
Changing the ACS's print function to have f:90.0 instead of just f:90 should help with that.
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Numberfields does not work? (Float expected)

Post by XASSASSINX »

Weird. If i use f:90.0 it gives me a "0" value everytime. Anything wrong with it?

Code: Select all

Script "PrintCostMessageMinigun" (void)
{
 Print(s:"This upgrade cost \ci", f:90.0 * GetCVar("cl_ScrapMultiplier"), s:" scraps. \c-Are you sure? (Use again)"); 
}
Edit: my theory is that it is somehow detecting f:90.0 as ONLY 0 * GetCvar... instead of 90.0 * GetCvar

Perhaps you have to use another letter that you forgot to put it in? This would explain as the value being 0. 0 * 0 = 0
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Numberfields does not work? (Float expected)

Post by Jarewill »

After reading more deeply into it, it turns out that GetCVar for ACS doesn't seem to return floats properly.
You could change the CVar to be an integer instead of a float and then do checks based on that:
Spoiler:
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Numberfields does not work? (Float expected)

Post by XASSASSINX »

Damn, a bit of a nasty workaround. i tried to do something along those lines:

Code: Select all

OptionValue "ScrapMultiplier" //Multiply scrap amount to upgrade of this value.
{
    0.25, "1x"
    0.50, "2x"
	0.75, "2.5x"
	1,    "1.5x"
	1.25, "2x"
	1.50, "2.5x"
	1.75, "1.75x"
	2,    "2x" 
	2.25, "2.25x"
	2.50, "2.5x"
}
BUUT It doesn't support it, which is very sad. Which it did though. Would make everyone lives easier.

Yeah, after analysing it, i thought of something similar, didn't know you could put such functions all together.
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Numberfields does not work? (Float expected)

Post by XASSASSINX »

Crap, it's still give me either the 0 value or the completely broken decimal value of 0.43413643653 or something. I think i will stick to the original, I will try something on later
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Numberfields does not work? (Float expected)

Post by Jarewill »

Could you post your code or upload a small example file so I could see what's wrong?
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Numberfields does not work? (Float expected)

Post by XASSASSINX »

The file is a problem as it is a big mod file. But here's the code: (In case if it's not enough, i will try to provide the minimum as to not give a bunch of non-useful stuff)

The CVARInfo:

Code: Select all

//Hello! This defines the scrap spawn rate, where they spawn, and some other stuff. Nothing too complex, i hope.
//Bool = Yes or no.
//Int = Any number or value, eg "Rarely, Normal, Frequent" (1, 2 ,3) and so on
//Just writing this to remind myself.
server int cl_ScrapMultiplier = 2;
server bool cl_HPnArmorSpawn = TRUE;
server int cl_HPnArmorSpawnChance = 4;
server bool cl_SmallAmmoSpawn = TRUE;
server int cl_SmallAmmoSpawnChance = 4;
server bool cl_BigAmmoSpawn = TRUE;
server int cl_BigAmmoSpawnChance = 4;

//Values for spawning  True Scavenger!, Very Rarely, Rarely, Normal, Frequent, Super Frequently,   Always
//Values according:         (5%)      ,    (15%)   ,  (25%),  (45%),   (75%) ,     (90%)       ,   (100%)
//This values in 256 bit will be like this: (12.8)	,	(38.4)	,	(64)	,	(115.2),	(192),	 (230.4)	,	(256) <-- Th
(The scrap multiplier was a bool, but i changed it in hope it would fix it, it didn't.)

The ScrapMultiplier part on the MenuDef:

Code: Select all

	//Slider "Multiply the amount of scrap required to upgrade.", "cl_ScrapMultiplier", 0.25, 2.5, 0.25, 2
	//NumberField "Multiply the amount of scrap required to upgrade.", "cl_ScrapMultiplier" ,0.25, 2.5, 0.25
	Option "Multiply the amount of scrap required to upgrade.", "cl_ScrapMultiplier", "ScrapMultiplier"
		StaticText "Multiply the amount of scrap required to upgrade by this value. "
		StaticText ""
The ACS to print the message: (The same as the one you gave me)

Code: Select all

Script "PrintCostMessageMinigun" (void)
{
 int mult;
 If(GetCVar("cl_ScrapMultiplier")==0){mult=0.25;}
 If(GetCVar("cl_ScrapMultiplier")==1){mult=0.5;}
 If(GetCVar("cl_ScrapMultiplier")==2){mult=0.75;}
 If(GetCVar("cl_ScrapMultiplier")==3){mult=1.0;}
 If(GetCVar("cl_ScrapMultiplier")==4){mult=1.25;}
 If(GetCVar("cl_ScrapMultiplier")==5){mult=1.5;}
 If(GetCVar("cl_ScrapMultiplier")==6){mult=1.75;}
 If(GetCVar("cl_ScrapMultiplier")==7){mult=2.0;}
 If(GetCVar("cl_ScrapMultiplier")==8){mult=2.25;}
 If(GetCVar("cl_ScrapMultiplier")==9){mult=2.5;}
 Print(s:"This upgrade cost \ci", f:FixedMul(90,mult), s:" scraps. \c-Are you sure? (Use again)"); 
}
And.. Yeah, that is pretty much it. Anything missing?
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Numberfields does not work? (Float expected)

Post by Jarewill »

It uses f:FixedMul(90,mult) in the Print function, when it should use f:FixedMul(90.0,mult).
That ".0" is very important in ACS scripts.
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Numberfields does not work? (Float expected)

Post by XASSASSINX »

I think i understood the problem. I fixed it, apparently some of the script were either wrong named OR i was using the wrong script. It still shows up as "value x.5" sometimes, but it's fine. I might one day do something to round it up, or maybe change to some value that will always end up in a rounded number, maybe. Anyways, thanks! Now i just need to align the Cvars with the script, as they are misligned and show the wrong cost and message.

Small edit: Hm, but how would it fit on the A_JumpIf decorate? Something like this:

Code: Select all

A_JumpIf(CountInv("GearInventory") >= (90 * (GetCVar("cl_ScrapMultiplier")==0){mult=0.25;}, 2)
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Numberfields does not work? (Float expected)

Post by Jarewill »

You could try this:

Code: Select all

A_JumpIf(CountInv("GearInventory") >= (90 * ((GetCVar("cl_ScrapMultiplier") * 0.25) + 0.25)), 2)
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Numberfields does not work? (Float expected)

Post by XASSASSINX »

Hm, now it's giving me the "Sprite name must be 4 frames exactly" error, which is weird, perhaps a typo?

Code: Select all

TNT1 A 0 A_TakeInventory("GearInventory") >= (90 * ((GetCVar("cl_ScrapMultiplier") * 0.25) + 0.25)), 2)
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Numberfields does not work? (Float expected)

Post by Jarewill »

You closed the function too early with brackets.
Try this:

Code: Select all

A_TakeInventory("GearInventory",(90 * ((GetCVar("cl_ScrapMultiplier") * 0.25) + 0.25)))
Post Reply

Return to “Scripting”