AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   % in string text (https://forums.alliedmods.net/showthread.php?t=266874)

NeXoU 07-21-2015 09:12

% in string text
 
Hello,

How can i display "%" in text, when i write % in text with Format, % does not appear.

PHP Code:

Format(testsizeof(test), "%d%"Pourcentage); // Don't work
Format(testsizeof(test), "%d\%"Pourcentage); // Don't work 

Thanks in advance

Icetea16 07-21-2015 09:24

Re: % in string text
 
Tien :

PHP Code:

#include <sdktools>

#define pourcent '%'

public Action OnClientPreAdminCheck(int client)
{
    
CreateTimer(5.0timer_TIMER_REPEAT);
}

public 
Action timer(Handle timer)
{
    
PrintToChatAll(" 5 %s"pourcent);



Miu 07-21-2015 09:27

Re: % in string text
 
%%

NeXoU 07-21-2015 09:33

Re: % in string text
 
Quote:

Originally Posted by Icetea16 (Post 2322664)
Tien :

PHP Code:

#include <sdktools>

#define pourcent '%'

public Action OnClientPreAdminCheck(int client)
{
    
CreateTimer(5.0timer_TIMER_REPEAT);
}

public 
Action timer(Handle timer)
{
    
PrintToChatAll(" 5 %s"pourcent);



--> Don't work

Quote:

Originally Posted by Miu (Post 2322665)
%%

--> Don't work

It's for Menu & Hud.

Thanks in advance

Icetea16 07-21-2015 09:45

Re: % in string text
 
1 Attachment(s)
Sa fonctionne

PHP Code:

#include <sdktools>

#pragma newdecls required

#define pourcent '%'

public Action OnClientPreAdminCheck(int client)
{
    
CreateTimer(5.0timerclientTIMER_REPEAT);
}

public 
Action timer(Handle timerany client)
{
    
char sText[64];
    
Format(sTextsizeof(sText), "5 %s"pourcent);
    
PrintToChatAll(sText);
    
    
Menu menu = new Menu(Menu_Test);
    
menu.SetTitle("titre");
    
menu.AddItem(""sText);
    
menu.ExitButton true;
    
menu.Display(client0);
}

public 
int Menu_Test(Menu menuMenuAction actionint clientint item)
{
    if (
action == MenuAction_Select)
    {
        
delete menu;
    }
    else if (
action == MenuAction_End)
    {
        
delete menu;
    }


Screenshot:

http://www.noelshack.com/2015-30-143...7-21-00002.jpg

KissLick 07-21-2015 09:52

Re: % in string text
 
This was mentioned here many times. The right answer is %%.

Always when the string is formated (Format, FormatEx, PrintTo* functions etc.) it converts %% to %.
So, if you format your string twice, you need to use %%%% - first format output is %% and second format output is %.

Icetea16 07-21-2015 09:55

Re: % in string text
 
Ok, good explanation.

I did not know

Powerlord 07-21-2015 10:01

Re: % in string text
 
If you need to print text that you've already formatted, pass it as a String argument to a format-class function.

For example:

Code:

char myString[32];
Format(myString, sizeof(myString), "%s", "5%");
PrintToChatAll("%s", myString);

This example is really contrived, but there are other reasons to do it. I ended up fixing a bug in colors.inc that was doing double formatting this way.

NeXoU 07-21-2015 10:02

Re: % in string text
 
Quote:

Format(BarreAnime[client], 64, "▄▄▄▄▄▄▄▄▄▄\n%d %%", Pourcentage);
I don't now why but it does not work :(

Thanks in advance

NeXoU 07-21-2015 19:05

Re: % in string text
 
It's fix.
Thank to all.


All times are GMT -4. The time now is 15:50.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.