AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Is it possible to show integer from string? (https://forums.alliedmods.net/showthread.php?t=253506)

KiLLeR. 12-23-2014 10:13

Is it possible to show integer from string?
 
PHP Code:

new const str[] = "%i text...";
new 
integer 5;

formatex(textcharsmax(text), "%s"strinteger

Output is "%i text...", but I want to be "5 text...", this is impossible?

Sorry if the title is wrong!

zmd94 12-23-2014 10:25

Re: It is possible to show integer from string?
 
Yes, you can.
PHP Code:

new const szString[] = "5 text" 


KiLLeR. 12-23-2014 10:36

Re: It is possible to show integer from string?
 
Quote:

Originally Posted by zmd94 (Post 2238964)
Yes, you can.
PHP Code:

new const szString[] = "5 text" 


No, no, no, this will not help me, because integer variable never has the same value. Just i gave above code for example.

zmd94 12-23-2014 10:43

Re: It is possible to show integer from string?
 
Then, maybe I misunderstood you. Actually, what you want to do?

Arkshine 12-23-2014 10:45

Re: It is possible to show integer from string?
 
Quote:

Originally Posted by KiLLeR. (Post 2238961)
PHP Code:

new const str[] = "%i text...";
new 
integer 5;

formatex(textcharsmax(text), "%s"strinteger

Output is "%i text...", but I want to be "5 text...", this is impossible?

Sorry if the title is wrong!


formatex(text, charsmax(text), str, integer)

zmd94 12-23-2014 11:16

Re: It is possible to show integer from string?
 
Quote:

formatex(text, charsmax(text), str, integer)
Alright, now I got it.

Then, is it right, if I do such below?
PHP Code:

new const str[] = "%i text %i text %i text %i text";
new 
integer1 1
new integer2 2
new integer3 3
new integer4 4

formatex
(textcharsmax(text), strinteger1integer2integer3integer4

So, the output is "1 text 2 text 3 text 4 text".

jimaway 12-23-2014 11:29

Re: It is possible to show integer from string?
 
looks right, did you try it?

zmd94 12-23-2014 12:20

Re: It is possible to show integer from string?
 
I have tested the code and it is working fine. Below is test code:
PHP Code:

#include <amxmodx>

new const str[] = "%i text %i text %i text %i text";
new 
integer1 1
new integer2 2
new integer3 3
new integer4 4

new text[101]

public 
plugin_init()
{
    
register_plugin("Test""1.0""zmd94")
    
    
register_clcmd("say /test""clcmd_test")
    
    
formatex(textcharsmax(text), strinteger1integer2integer3integer4
}

public 
clcmd_test(id)
{
    
client_print(idprint_chat"%s"text)



Bugsy 12-23-2014 18:09

Re: It is possible to show integer from string?
 
zmd94, that code is totally fine.

FYI, you can do this instead of the "%s", as long as the variable you are passing is a string:

PHP Code:

client_print(idprint_chattext


zmd94 12-23-2014 21:45

Re: It is possible to show integer from string?
 
I don't know that, Bugsy. I appreciate it as I'm also still learning. ;)


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

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