C# How to store a float and read it in a function
I'm very new to programming and I know this is simple answer but I for the life of me can't figure it out.
public float getCurrentY()
{
float CurrentY = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
return CurrentY;
}
When I toggle box is checked it gets the current Y
private void CITFlightTestToggle_CheckedChanged(object sender, EventArgs e)
{
if (CITFlightTestToggle.Checked == true)
{
getCurrentY();
}
else if (CITFlightTestToggle.Checked == false)
{
}
}
I basically want the value of the current why at the time of when the player checks the toggle box and then add a value from a trackbar onto that stored value. The problem is it keeps getting the currentY when you move the trackbar and the current Y keeps changing since I am adding to it.
private void CITFlyingHeightTrackBar_Scroll_1(object sender, ScrollEventArgs e)
{
float diviedflyingheight = CITFlyingHeightTrackBar.Value / 10f;
float current_num = getCurrentY();
float flyingheightadded = current_num + diviedflyingheight;
if (CITFlightTestToggle.Checked == true)
if (levelchecktext == Variables.CIT_LVL_GREAT_CLOCK_A)
{
API.Extension.WriteFloat(Variables.CIT_GCA_Y_COORD, (flyingheightadded));
}
else
{
}
}
thanks in advance
c# function floating-point
add a comment |
I'm very new to programming and I know this is simple answer but I for the life of me can't figure it out.
public float getCurrentY()
{
float CurrentY = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
return CurrentY;
}
When I toggle box is checked it gets the current Y
private void CITFlightTestToggle_CheckedChanged(object sender, EventArgs e)
{
if (CITFlightTestToggle.Checked == true)
{
getCurrentY();
}
else if (CITFlightTestToggle.Checked == false)
{
}
}
I basically want the value of the current why at the time of when the player checks the toggle box and then add a value from a trackbar onto that stored value. The problem is it keeps getting the currentY when you move the trackbar and the current Y keeps changing since I am adding to it.
private void CITFlyingHeightTrackBar_Scroll_1(object sender, ScrollEventArgs e)
{
float diviedflyingheight = CITFlyingHeightTrackBar.Value / 10f;
float current_num = getCurrentY();
float flyingheightadded = current_num + diviedflyingheight;
if (CITFlightTestToggle.Checked == true)
if (levelchecktext == Variables.CIT_LVL_GREAT_CLOCK_A)
{
API.Extension.WriteFloat(Variables.CIT_GCA_Y_COORD, (flyingheightadded));
}
else
{
}
}
thanks in advance
c# function floating-point
1
A "get" type call should probably be a function. CurrentY sounds like it shouldn't be a string.public float GetCurrentY()
is probably how it should be written, and have it return the value. Get rid of the CITCurrentYString since you only have it local to that method, so you never get to use the value.
– LarsTech
Nov 22 '18 at 18:32
add a comment |
I'm very new to programming and I know this is simple answer but I for the life of me can't figure it out.
public float getCurrentY()
{
float CurrentY = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
return CurrentY;
}
When I toggle box is checked it gets the current Y
private void CITFlightTestToggle_CheckedChanged(object sender, EventArgs e)
{
if (CITFlightTestToggle.Checked == true)
{
getCurrentY();
}
else if (CITFlightTestToggle.Checked == false)
{
}
}
I basically want the value of the current why at the time of when the player checks the toggle box and then add a value from a trackbar onto that stored value. The problem is it keeps getting the currentY when you move the trackbar and the current Y keeps changing since I am adding to it.
private void CITFlyingHeightTrackBar_Scroll_1(object sender, ScrollEventArgs e)
{
float diviedflyingheight = CITFlyingHeightTrackBar.Value / 10f;
float current_num = getCurrentY();
float flyingheightadded = current_num + diviedflyingheight;
if (CITFlightTestToggle.Checked == true)
if (levelchecktext == Variables.CIT_LVL_GREAT_CLOCK_A)
{
API.Extension.WriteFloat(Variables.CIT_GCA_Y_COORD, (flyingheightadded));
}
else
{
}
}
thanks in advance
c# function floating-point
I'm very new to programming and I know this is simple answer but I for the life of me can't figure it out.
public float getCurrentY()
{
float CurrentY = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
return CurrentY;
}
When I toggle box is checked it gets the current Y
private void CITFlightTestToggle_CheckedChanged(object sender, EventArgs e)
{
if (CITFlightTestToggle.Checked == true)
{
getCurrentY();
}
else if (CITFlightTestToggle.Checked == false)
{
}
}
I basically want the value of the current why at the time of when the player checks the toggle box and then add a value from a trackbar onto that stored value. The problem is it keeps getting the currentY when you move the trackbar and the current Y keeps changing since I am adding to it.
private void CITFlyingHeightTrackBar_Scroll_1(object sender, ScrollEventArgs e)
{
float diviedflyingheight = CITFlyingHeightTrackBar.Value / 10f;
float current_num = getCurrentY();
float flyingheightadded = current_num + diviedflyingheight;
if (CITFlightTestToggle.Checked == true)
if (levelchecktext == Variables.CIT_LVL_GREAT_CLOCK_A)
{
API.Extension.WriteFloat(Variables.CIT_GCA_Y_COORD, (flyingheightadded));
}
else
{
}
}
thanks in advance
c# function floating-point
c# function floating-point
edited Nov 22 '18 at 19:16
frying_pan
asked Nov 22 '18 at 18:27
frying_panfrying_pan
12
12
1
A "get" type call should probably be a function. CurrentY sounds like it shouldn't be a string.public float GetCurrentY()
is probably how it should be written, and have it return the value. Get rid of the CITCurrentYString since you only have it local to that method, so you never get to use the value.
– LarsTech
Nov 22 '18 at 18:32
add a comment |
1
A "get" type call should probably be a function. CurrentY sounds like it shouldn't be a string.public float GetCurrentY()
is probably how it should be written, and have it return the value. Get rid of the CITCurrentYString since you only have it local to that method, so you never get to use the value.
– LarsTech
Nov 22 '18 at 18:32
1
1
A "get" type call should probably be a function. CurrentY sounds like it shouldn't be a string.
public float GetCurrentY()
is probably how it should be written, and have it return the value. Get rid of the CITCurrentYString since you only have it local to that method, so you never get to use the value.– LarsTech
Nov 22 '18 at 18:32
A "get" type call should probably be a function. CurrentY sounds like it shouldn't be a string.
public float GetCurrentY()
is probably how it should be written, and have it return the value. Get rid of the CITCurrentYString since you only have it local to that method, so you never get to use the value.– LarsTech
Nov 22 '18 at 18:32
add a comment |
1 Answer
1
active
oldest
votes
welcome to stack overflow
you see that word "void" in your method declaration? That's the return type. You change that to string, and then use the "return" keyword to select the value it returns.
public string getCurrentY()
{
string CITCurrentYString = null;
float CurrentY = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
CITCurrentYString = (CurrentY.ToString());
return CITCurrentYString;
}
Is there a reason you are converting to a string though? It looks like you really need a float. Like this
public float getCurrentY()
{
float CurrentY = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
return CurrentY;
}
private void CITFlyingHeightTrackBar_Scroll_1(object sender, ScrollEventArgs e)
{
float current_num = getCurrentY();
}
even shorter,float current_num = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
, assuming API is a namespace or static class
– trollingchar
Nov 22 '18 at 18:38
yup, I saw that, but since this was the OPs first question, I figured answering the "how do I return a value" question was more important
– Broom
Nov 22 '18 at 18:39
Thanks for the help. the problem is I dont want currentY to be written everytime the trackbar is moved. I bascially want that float to be stored and then the trackbar value added onto it. originally i created a label made it invisible and just converted the float to text and parsed it and that's how i stored the value (you select a checkbox and then it calls the getCurrentY) but I figured there must be a better way
– frying_pan
Nov 22 '18 at 18:51
1
aha, looks like we have an XY problem here. meta.stackexchange.com/questions/66377/what-is-the-xy-problem Where are you actually using this value?
– Broom
Nov 22 '18 at 18:55
I updated my original code to show it. XY problem is exactly what I have now I'm attempting to learn the proper way lol
– frying_pan
Nov 22 '18 at 19:04
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436464%2fc-sharp-how-to-store-a-float-and-read-it-in-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
welcome to stack overflow
you see that word "void" in your method declaration? That's the return type. You change that to string, and then use the "return" keyword to select the value it returns.
public string getCurrentY()
{
string CITCurrentYString = null;
float CurrentY = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
CITCurrentYString = (CurrentY.ToString());
return CITCurrentYString;
}
Is there a reason you are converting to a string though? It looks like you really need a float. Like this
public float getCurrentY()
{
float CurrentY = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
return CurrentY;
}
private void CITFlyingHeightTrackBar_Scroll_1(object sender, ScrollEventArgs e)
{
float current_num = getCurrentY();
}
even shorter,float current_num = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
, assuming API is a namespace or static class
– trollingchar
Nov 22 '18 at 18:38
yup, I saw that, but since this was the OPs first question, I figured answering the "how do I return a value" question was more important
– Broom
Nov 22 '18 at 18:39
Thanks for the help. the problem is I dont want currentY to be written everytime the trackbar is moved. I bascially want that float to be stored and then the trackbar value added onto it. originally i created a label made it invisible and just converted the float to text and parsed it and that's how i stored the value (you select a checkbox and then it calls the getCurrentY) but I figured there must be a better way
– frying_pan
Nov 22 '18 at 18:51
1
aha, looks like we have an XY problem here. meta.stackexchange.com/questions/66377/what-is-the-xy-problem Where are you actually using this value?
– Broom
Nov 22 '18 at 18:55
I updated my original code to show it. XY problem is exactly what I have now I'm attempting to learn the proper way lol
– frying_pan
Nov 22 '18 at 19:04
add a comment |
welcome to stack overflow
you see that word "void" in your method declaration? That's the return type. You change that to string, and then use the "return" keyword to select the value it returns.
public string getCurrentY()
{
string CITCurrentYString = null;
float CurrentY = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
CITCurrentYString = (CurrentY.ToString());
return CITCurrentYString;
}
Is there a reason you are converting to a string though? It looks like you really need a float. Like this
public float getCurrentY()
{
float CurrentY = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
return CurrentY;
}
private void CITFlyingHeightTrackBar_Scroll_1(object sender, ScrollEventArgs e)
{
float current_num = getCurrentY();
}
even shorter,float current_num = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
, assuming API is a namespace or static class
– trollingchar
Nov 22 '18 at 18:38
yup, I saw that, but since this was the OPs first question, I figured answering the "how do I return a value" question was more important
– Broom
Nov 22 '18 at 18:39
Thanks for the help. the problem is I dont want currentY to be written everytime the trackbar is moved. I bascially want that float to be stored and then the trackbar value added onto it. originally i created a label made it invisible and just converted the float to text and parsed it and that's how i stored the value (you select a checkbox and then it calls the getCurrentY) but I figured there must be a better way
– frying_pan
Nov 22 '18 at 18:51
1
aha, looks like we have an XY problem here. meta.stackexchange.com/questions/66377/what-is-the-xy-problem Where are you actually using this value?
– Broom
Nov 22 '18 at 18:55
I updated my original code to show it. XY problem is exactly what I have now I'm attempting to learn the proper way lol
– frying_pan
Nov 22 '18 at 19:04
add a comment |
welcome to stack overflow
you see that word "void" in your method declaration? That's the return type. You change that to string, and then use the "return" keyword to select the value it returns.
public string getCurrentY()
{
string CITCurrentYString = null;
float CurrentY = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
CITCurrentYString = (CurrentY.ToString());
return CITCurrentYString;
}
Is there a reason you are converting to a string though? It looks like you really need a float. Like this
public float getCurrentY()
{
float CurrentY = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
return CurrentY;
}
private void CITFlyingHeightTrackBar_Scroll_1(object sender, ScrollEventArgs e)
{
float current_num = getCurrentY();
}
welcome to stack overflow
you see that word "void" in your method declaration? That's the return type. You change that to string, and then use the "return" keyword to select the value it returns.
public string getCurrentY()
{
string CITCurrentYString = null;
float CurrentY = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
CITCurrentYString = (CurrentY.ToString());
return CITCurrentYString;
}
Is there a reason you are converting to a string though? It looks like you really need a float. Like this
public float getCurrentY()
{
float CurrentY = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
return CurrentY;
}
private void CITFlyingHeightTrackBar_Scroll_1(object sender, ScrollEventArgs e)
{
float current_num = getCurrentY();
}
answered Nov 22 '18 at 18:35
BroomBroom
460215
460215
even shorter,float current_num = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
, assuming API is a namespace or static class
– trollingchar
Nov 22 '18 at 18:38
yup, I saw that, but since this was the OPs first question, I figured answering the "how do I return a value" question was more important
– Broom
Nov 22 '18 at 18:39
Thanks for the help. the problem is I dont want currentY to be written everytime the trackbar is moved. I bascially want that float to be stored and then the trackbar value added onto it. originally i created a label made it invisible and just converted the float to text and parsed it and that's how i stored the value (you select a checkbox and then it calls the getCurrentY) but I figured there must be a better way
– frying_pan
Nov 22 '18 at 18:51
1
aha, looks like we have an XY problem here. meta.stackexchange.com/questions/66377/what-is-the-xy-problem Where are you actually using this value?
– Broom
Nov 22 '18 at 18:55
I updated my original code to show it. XY problem is exactly what I have now I'm attempting to learn the proper way lol
– frying_pan
Nov 22 '18 at 19:04
add a comment |
even shorter,float current_num = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
, assuming API is a namespace or static class
– trollingchar
Nov 22 '18 at 18:38
yup, I saw that, but since this was the OPs first question, I figured answering the "how do I return a value" question was more important
– Broom
Nov 22 '18 at 18:39
Thanks for the help. the problem is I dont want currentY to be written everytime the trackbar is moved. I bascially want that float to be stored and then the trackbar value added onto it. originally i created a label made it invisible and just converted the float to text and parsed it and that's how i stored the value (you select a checkbox and then it calls the getCurrentY) but I figured there must be a better way
– frying_pan
Nov 22 '18 at 18:51
1
aha, looks like we have an XY problem here. meta.stackexchange.com/questions/66377/what-is-the-xy-problem Where are you actually using this value?
– Broom
Nov 22 '18 at 18:55
I updated my original code to show it. XY problem is exactly what I have now I'm attempting to learn the proper way lol
– frying_pan
Nov 22 '18 at 19:04
even shorter,
float current_num = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
, assuming API is a namespace or static class– trollingchar
Nov 22 '18 at 18:38
even shorter,
float current_num = API.Extension.ReadFloat(Variables.CIT_PLAYER_Y_COORD);
, assuming API is a namespace or static class– trollingchar
Nov 22 '18 at 18:38
yup, I saw that, but since this was the OPs first question, I figured answering the "how do I return a value" question was more important
– Broom
Nov 22 '18 at 18:39
yup, I saw that, but since this was the OPs first question, I figured answering the "how do I return a value" question was more important
– Broom
Nov 22 '18 at 18:39
Thanks for the help. the problem is I dont want currentY to be written everytime the trackbar is moved. I bascially want that float to be stored and then the trackbar value added onto it. originally i created a label made it invisible and just converted the float to text and parsed it and that's how i stored the value (you select a checkbox and then it calls the getCurrentY) but I figured there must be a better way
– frying_pan
Nov 22 '18 at 18:51
Thanks for the help. the problem is I dont want currentY to be written everytime the trackbar is moved. I bascially want that float to be stored and then the trackbar value added onto it. originally i created a label made it invisible and just converted the float to text and parsed it and that's how i stored the value (you select a checkbox and then it calls the getCurrentY) but I figured there must be a better way
– frying_pan
Nov 22 '18 at 18:51
1
1
aha, looks like we have an XY problem here. meta.stackexchange.com/questions/66377/what-is-the-xy-problem Where are you actually using this value?
– Broom
Nov 22 '18 at 18:55
aha, looks like we have an XY problem here. meta.stackexchange.com/questions/66377/what-is-the-xy-problem Where are you actually using this value?
– Broom
Nov 22 '18 at 18:55
I updated my original code to show it. XY problem is exactly what I have now I'm attempting to learn the proper way lol
– frying_pan
Nov 22 '18 at 19:04
I updated my original code to show it. XY problem is exactly what I have now I'm attempting to learn the proper way lol
– frying_pan
Nov 22 '18 at 19:04
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436464%2fc-sharp-how-to-store-a-float-and-read-it-in-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
A "get" type call should probably be a function. CurrentY sounds like it shouldn't be a string.
public float GetCurrentY()
is probably how it should be written, and have it return the value. Get rid of the CITCurrentYString since you only have it local to that method, so you never get to use the value.– LarsTech
Nov 22 '18 at 18:32