Raised This Month: $12 Target: $400
 3% 

Help with setting convar


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Agret
Member
Join Date: Jan 2005
Location: Melbourne, Victoria
Old 09-16-2008 , 02:25   Help with setting convar
Reply With Quote #1

Excuse the formatting, was asking in SourceMod IRC but got no reply (yet?)

17:16 Agret Hello
17:16 Agret i'm writing a plugin that reads a text file line by line
17:17 Agret it then uses BreakString to get the first part of the string as the comparison and if it matches the map name it will set the downloadurl to the index as defined by the return of BreakString
17:17 Agret the problem is if i use line[pos] to get the rest of the line
17:17 Agret it will get the newline
17:18 Agret and set my downloadurl to http://;blah/<newline>
17:18 Agret obviously this is a bit of an issue
17:18 Agret so i attempted to make it set the downloadurl, read it back then use the strip function to remove whitespace and then set that new string back as the downloadurl
17:18 Agret however it was giving me an issue about 'array not indexed' or something
17:19 Agret so i had to do fix[0] = trim(downloadurl)
17:19 Agret but then the first character is cut off
17:19 Agret so the download url becomes " ttp/blah"
17:19 Agret (replacing the h with a space)
17:19 Agret how can i strip the newline when setting the string?
17:20 Agret SetConVarString(g_hDownloadURL, line[pos])
17:21 Agret logically (to me) i tried SetConVarString(g_hDownloadURL, trim(line[pos]))
17:21 Agret but it doesnt work
Attached Files
File Type: sp Get Plugin or Get Source (downloadurl.sp - 587 views - 2.3 KB)
__________________

(¯`·._¤²°°²Agret²°°²¤_.·´¯)
¸.-~·*'˜¨¯Ï”m_†hê_ôñë_åñd_õñl¥_Åg®ê†¨˜'*·~-.¸

Last edited by Agret; 09-16-2008 at 04:07.
Agret is offline
Send a message via ICQ to Agret Send a message via AIM to Agret Send a message via MSN to Agret Send a message via Yahoo to Agret
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 09-16-2008 , 08:56   Re: Help with setting convar
Reply With Quote #2

PHP Code:
new len strlen(line);
if (
line[len-1] == '\n')
{
    
line[len-1] = '\0';

bl4nk is offline
Agret
Member
Join Date: Jan 2005
Location: Melbourne, Victoria
Old 09-16-2008 , 11:19   Re: Help with setting convar
Reply With Quote #3

I added your fix but it doesn't compile now,
Quote:
//// downloadurl.sp
// downloadurl.sp(102) : error 022: must be lvalue (non-constant)
// downloadurl.sp(102) : warning 215: expression has no effect
//
// 1 Error.
//
// Compilation Time: 0.2 sec
// ----------------------------------------
Your fix seems logically sound to me, I must be passing the variable to it wrong though.
This is the first SourceMod script i've written (previously written amxmodx scripts, about a year ago) and i'm still not used to the different variable types.
Attached Files
File Type: sp Get Plugin or Get Source (downloadurl.sp - 169 views - 2.5 KB)
__________________

(¯`·._¤²°°²Agret²°°²¤_.·´¯)
¸.-~·*'˜¨¯Ï”m_†hê_ôñë_åñd_õñl¥_Åg®ê†¨˜'*·~-.¸
Agret is offline
Send a message via ICQ to Agret Send a message via AIM to Agret Send a message via MSN to Agret Send a message via Yahoo to Agret
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 09-16-2008 , 11:28   Re: Help with setting convar
Reply With Quote #4

You defined "line" as a constant string, meaning you can't change the value of it, and that's exactly what you're trying to do there.
bl4nk is offline
Agret
Member
Join Date: Jan 2005
Location: Melbourne, Victoria
Old 09-16-2008 , 22:11   Re: Help with setting convar
Reply With Quote #5

Ohhh, I see what I did wrong. Thank you bl4nk. Plugin is working great now

Although my plugin works properly now I have to ask, does anyone see any improvements I could make in the way the plugin is coded.
I'm interested in advancing my knowledge of how you should code and whatever improvements can be made to it.
Attached Files
File Type: sp Get Plugin or Get Source (downloadurl.sp - 617 views - 2.5 KB)
__________________

(¯`·._¤²°°²Agret²°°²¤_.·´¯)
¸.-~·*'˜¨¯Ï”m_†hê_ôñë_åñd_õñl¥_Åg®ê†¨˜'*·~-.¸
Agret is offline
Send a message via ICQ to Agret Send a message via AIM to Agret Send a message via MSN to Agret Send a message via Yahoo to Agret
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 17:52.


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