SetCVar/GetCVar refuse to work (with custom cvars)

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
SFJake
Posts: 531
Joined: Sat Nov 03, 2007 11:28 am

SetCVar/GetCVar refuse to work (with custom cvars)

Post by SFJake »

Alright, this is weirding me out. I've never used this, but I've wanted a RPG-system that carries between games, and I wanted to use these for that purpose. (purely for single player purposes)


The idea is simple, right? SetCVar to save the experience/level of the user, and GetCVar when the player starts a new game to set his xp/level to what it was.


However, the 2 commands don't behave.

This is my CVARINFO:

user int SFPlayerXP;
user int SFPlayerLevel;


I use SetCVar like this:

SetCVar("SFPlayerXP", "exp");

Where as "exp" is an int based on the player's XP. However, despite "exp" being 1, it saves itself in the ini as SFPlayerXP=2146435081. Why?

The core of the problem, though, is GetCVar. It does not work. I've tried the following:

int sfcvarplayerxp = GetCVar ("SFPlayerXP");

And

GiveInventory ("SFPlayerXP", (GetCVar ("SFPlayerXP")));

Either way, the console will tell me:

ACS: I don't know what SFPlayerXP is.

Thus I'm unable to do anything.

Ugh. How do these things work? What am I missing?
User avatar
Rachael
Posts: 13960
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: SetCVar/GetCVar refuse to work (with custom cvars)

Post by Rachael »

What does your CVARINFO look like?
User avatar
SFJake
Posts: 531
Joined: Sat Nov 03, 2007 11:28 am

Re: SetCVar/GetCVar refuse to work (with custom cvars)

Post by SFJake »

Sorry, my post is a bit of a mess but it is there:
SFJake wrote: user int SFPlayerXP;
user int SFPlayerLevel;
User avatar
Rachael
Posts: 13960
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: SetCVar/GetCVar refuse to work (with custom cvars)

Post by Rachael »

I didn't see it, sorry.

What stands out for me is this:

Code: Select all

SetCVar("SFPlayerXP", "exp");
You quoted "exp" - why? That makes it a string and that is inherently incompatible with Int CVars.

But I don't know if that's what's wrong here, unless the error message is misleading.
User avatar
SFJake
Posts: 531
Joined: Sat Nov 03, 2007 11:28 am

Re: SetCVar/GetCVar refuse to work (with custom cvars)

Post by SFJake »

Yeah, I feel insanely stupid right now, happens sometimes when I tunnel vision into something.


It was what you said for SetCVar, simple syntax error, but the GetCVar didn't work because I didn't use the right inventory item name in the next lines in the script, I used the names of the CVars. Since I was seeing them as an error, I thought it was the cvar and just never checked the inventory names. (until now)


I knew it, though. Its always a dumb mistake that brings me to a forum asking for scripting/coding help. Thanks for trying to help!
User avatar
Rachael
Posts: 13960
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: SetCVar/GetCVar refuse to work (with custom cvars)

Post by Rachael »

Happens to me too. You're welcome.
Locked

Return to “Editing (Archive)”