Raised This Month: $ Target: $400
 0% 

Type casting


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ilham92-cc-sakura
Senior Member
Join Date: Oct 2008
Location: /var/www/index.html
Old 02-13-2014 , 10:38   Type casting
Reply With Quote #1

Like in C,
Code:
#include <stdio.h>
void main(){
     float a=65.4;
     printf("number is %d = %c", (int)a, (char)a);
}
how to cast/convert data type in Source Mod?
__________________

Last edited by ilham92-cc-sakura; 02-13-2014 at 10:44.
ilham92-cc-sakura is offline
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 02-13-2014 , 11:07   Re: Type casting
Reply With Quote #2

new a = 100;
new Float b;

b = Float:a;
a = _:b;
h3bus is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 02-13-2014 , 11:51   Re: Type casting
Reply With Quote #3

Afaik casting is actually not possible because there is no automatic data conversion in Sourcepawn.
All you can do is, to "tag" a variable into another datatype. For float / cell (int) conversion you actually have to use the proper functions if you don't want to end with garbish data.

PHP Code:
// Float to cell
new integer RoundToCeil(5.3); // Conversion to int and tag change by function
// 4 rounding functions exist: RoundToZero, RoundToCeil, RoundToFloor, RoundToNearest

// Cell to float
new Float:floating float(5);  // Conversion to int and tag change by function

// Hardcode a new tag (-type)
new Handle:tagChange Handle:5// This would tag a number as handle (This is just an example, you shouldn't actually do this). 
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 02-13-2014 at 11:53.
berni is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:14.


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