R: How to modify values of slots?










0















I'm newbie in R and I have defined an object with one method called "show". In this method I modify the value of a slot and then I print to show its value. The value is correct.



method(show)



setMethod("show", "menu", function(object)
while (TRUE)
#Clean console
cat("14")
cat("COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICIONn")
cat("-------------------------------------------------nn")
cat("1. Comparativa entre clubes de Liga DIAn")
cat("2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'n")
cat("3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'n")
cat("0. Salirnn")
option <- readline("Selecciona opción: ")
option <- suppressWarnings(as.numeric(option))
if (!is.na(option))
if (option == 1)
object@competition <- 14

if (option == 2)
object@competition <- 22

if (option == 3)
object@competition <- 23

print(object@competition)
readline("Espera ...")
if (option == 0)
break
else
readline("No es un número. Pulsa una tecla para introducir otra opción.")


)


But If I try to access to the slot outside this method I've got the initial value.



x <- menu(competition=0, stats=0)
x
print(x@competition)


When I call "x" I'm calling the "show" method too and inside of them I give a value to "competition" different to 0. But, later, when I try to print the value with print(x@competition) I've got like result 0.



> print(x@competition)
[1] 0


I would like to get the value assigned inside "show" method but I've got the value when I create the object. How can I modify the value of the slot correctly?










share|improve this question






















  • This is a shot in the dark but maybe it is similar to defining objects in the global environment from within a function, i.e. using <<- instead of <-.

    – nate.edwinton
    Nov 13 '18 at 10:43











  • Thank you @nate.edwinton but I've got an error If use <<- insted of <- inside the function when I give the value to the slot. If I use when I create the object x <<- menu(competition=0, stats=0) later I still get the the value assigned when I create the object and not the value that I assign inside show method. :(

    – José Carlos
    Nov 13 '18 at 10:55











  • I just added a return(object) statement in the function and break statements in the if(... == x). I believe it does what you expect now, see the edit.

    – nate.edwinton
    Nov 13 '18 at 11:34
















0















I'm newbie in R and I have defined an object with one method called "show". In this method I modify the value of a slot and then I print to show its value. The value is correct.



method(show)



setMethod("show", "menu", function(object)
while (TRUE)
#Clean console
cat("14")
cat("COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICIONn")
cat("-------------------------------------------------nn")
cat("1. Comparativa entre clubes de Liga DIAn")
cat("2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'n")
cat("3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'n")
cat("0. Salirnn")
option <- readline("Selecciona opción: ")
option <- suppressWarnings(as.numeric(option))
if (!is.na(option))
if (option == 1)
object@competition <- 14

if (option == 2)
object@competition <- 22

if (option == 3)
object@competition <- 23

print(object@competition)
readline("Espera ...")
if (option == 0)
break
else
readline("No es un número. Pulsa una tecla para introducir otra opción.")


)


But If I try to access to the slot outside this method I've got the initial value.



x <- menu(competition=0, stats=0)
x
print(x@competition)


When I call "x" I'm calling the "show" method too and inside of them I give a value to "competition" different to 0. But, later, when I try to print the value with print(x@competition) I've got like result 0.



> print(x@competition)
[1] 0


I would like to get the value assigned inside "show" method but I've got the value when I create the object. How can I modify the value of the slot correctly?










share|improve this question






















  • This is a shot in the dark but maybe it is similar to defining objects in the global environment from within a function, i.e. using <<- instead of <-.

    – nate.edwinton
    Nov 13 '18 at 10:43











  • Thank you @nate.edwinton but I've got an error If use <<- insted of <- inside the function when I give the value to the slot. If I use when I create the object x <<- menu(competition=0, stats=0) later I still get the the value assigned when I create the object and not the value that I assign inside show method. :(

    – José Carlos
    Nov 13 '18 at 10:55











  • I just added a return(object) statement in the function and break statements in the if(... == x). I believe it does what you expect now, see the edit.

    – nate.edwinton
    Nov 13 '18 at 11:34














0












0








0








I'm newbie in R and I have defined an object with one method called "show". In this method I modify the value of a slot and then I print to show its value. The value is correct.



method(show)



setMethod("show", "menu", function(object)
while (TRUE)
#Clean console
cat("14")
cat("COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICIONn")
cat("-------------------------------------------------nn")
cat("1. Comparativa entre clubes de Liga DIAn")
cat("2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'n")
cat("3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'n")
cat("0. Salirnn")
option <- readline("Selecciona opción: ")
option <- suppressWarnings(as.numeric(option))
if (!is.na(option))
if (option == 1)
object@competition <- 14

if (option == 2)
object@competition <- 22

if (option == 3)
object@competition <- 23

print(object@competition)
readline("Espera ...")
if (option == 0)
break
else
readline("No es un número. Pulsa una tecla para introducir otra opción.")


)


But If I try to access to the slot outside this method I've got the initial value.



x <- menu(competition=0, stats=0)
x
print(x@competition)


When I call "x" I'm calling the "show" method too and inside of them I give a value to "competition" different to 0. But, later, when I try to print the value with print(x@competition) I've got like result 0.



> print(x@competition)
[1] 0


I would like to get the value assigned inside "show" method but I've got the value when I create the object. How can I modify the value of the slot correctly?










share|improve this question














I'm newbie in R and I have defined an object with one method called "show". In this method I modify the value of a slot and then I print to show its value. The value is correct.



method(show)



setMethod("show", "menu", function(object)
while (TRUE)
#Clean console
cat("14")
cat("COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICIONn")
cat("-------------------------------------------------nn")
cat("1. Comparativa entre clubes de Liga DIAn")
cat("2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'n")
cat("3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'n")
cat("0. Salirnn")
option <- readline("Selecciona opción: ")
option <- suppressWarnings(as.numeric(option))
if (!is.na(option))
if (option == 1)
object@competition <- 14

if (option == 2)
object@competition <- 22

if (option == 3)
object@competition <- 23

print(object@competition)
readline("Espera ...")
if (option == 0)
break
else
readline("No es un número. Pulsa una tecla para introducir otra opción.")


)


But If I try to access to the slot outside this method I've got the initial value.



x <- menu(competition=0, stats=0)
x
print(x@competition)


When I call "x" I'm calling the "show" method too and inside of them I give a value to "competition" different to 0. But, later, when I try to print the value with print(x@competition) I've got like result 0.



> print(x@competition)
[1] 0


I would like to get the value assigned inside "show" method but I've got the value when I create the object. How can I modify the value of the slot correctly?







r oop






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 10:35









José CarlosJosé Carlos

68821944




68821944












  • This is a shot in the dark but maybe it is similar to defining objects in the global environment from within a function, i.e. using <<- instead of <-.

    – nate.edwinton
    Nov 13 '18 at 10:43











  • Thank you @nate.edwinton but I've got an error If use <<- insted of <- inside the function when I give the value to the slot. If I use when I create the object x <<- menu(competition=0, stats=0) later I still get the the value assigned when I create the object and not the value that I assign inside show method. :(

    – José Carlos
    Nov 13 '18 at 10:55











  • I just added a return(object) statement in the function and break statements in the if(... == x). I believe it does what you expect now, see the edit.

    – nate.edwinton
    Nov 13 '18 at 11:34


















  • This is a shot in the dark but maybe it is similar to defining objects in the global environment from within a function, i.e. using <<- instead of <-.

    – nate.edwinton
    Nov 13 '18 at 10:43











  • Thank you @nate.edwinton but I've got an error If use <<- insted of <- inside the function when I give the value to the slot. If I use when I create the object x <<- menu(competition=0, stats=0) later I still get the the value assigned when I create the object and not the value that I assign inside show method. :(

    – José Carlos
    Nov 13 '18 at 10:55











  • I just added a return(object) statement in the function and break statements in the if(... == x). I believe it does what you expect now, see the edit.

    – nate.edwinton
    Nov 13 '18 at 11:34

















This is a shot in the dark but maybe it is similar to defining objects in the global environment from within a function, i.e. using <<- instead of <-.

– nate.edwinton
Nov 13 '18 at 10:43





This is a shot in the dark but maybe it is similar to defining objects in the global environment from within a function, i.e. using <<- instead of <-.

– nate.edwinton
Nov 13 '18 at 10:43













Thank you @nate.edwinton but I've got an error If use <<- insted of <- inside the function when I give the value to the slot. If I use when I create the object x <<- menu(competition=0, stats=0) later I still get the the value assigned when I create the object and not the value that I assign inside show method. :(

– José Carlos
Nov 13 '18 at 10:55





Thank you @nate.edwinton but I've got an error If use <<- insted of <- inside the function when I give the value to the slot. If I use when I create the object x <<- menu(competition=0, stats=0) later I still get the the value assigned when I create the object and not the value that I assign inside show method. :(

– José Carlos
Nov 13 '18 at 10:55













I just added a return(object) statement in the function and break statements in the if(... == x). I believe it does what you expect now, see the edit.

– nate.edwinton
Nov 13 '18 at 11:34






I just added a return(object) statement in the function and break statements in the if(... == x). I believe it does what you expect now, see the edit.

– nate.edwinton
Nov 13 '18 at 11:34













1 Answer
1






active

oldest

votes


















1














Okay so here are a couple of lines that helped for me:



myFun <- function(object) 0
setGeneric("myFun")
setClass("myClass", slots = c("competition", "stats"))


I then proceed with your code (slightly modified the the setMethod):



setMethod("myFun", "myClass", function(object)
while (TRUE)
#Clean console
cat("14")
cat("COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICIONn")
cat("-------------------------------------------------nn")
cat("1. Comparativa entre clubes de Liga DIAn")
cat("2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'n")
cat("3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'n")
cat("0. Salirnn")
option <- readline("Selecciona opción: ")
option <- suppressWarnings(as.numeric(option))
if (!is.na(option))
if (option == 1)
object@competition <- 14
break

if (option == 2)
object@competition <- 22
break

if (option == 3)
object@competition <- 23
break

print(object@competition)
readline("Espera ...")
if (option == 0)
break
else
readline("No es un número. Pulsa una tecla para introducir otra opción.")


return(object)
)


Here is my output:



x <- new("myClass", competition = 0, stats = 0)
# printing just x yields:
An object of class "myClass"
Slot "competition":
[1] 0

Slot "stats":
[1] 0

# Here is what myFun(x) yields:
COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICION
-------------------------------------------------

1. Comparativa entre clubes de Liga DIA
2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'
3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'
0. Salir

Selecciona opción:
# hits 1
An object of class "myClass"
Slot "competition":
[1] 14

Slot "stats":
[1] 0


Now setting y <- myFun(x), we obtain (again hitting 1 in the console):



> print(y@competition)
[1] 14





share|improve this answer

























  • Yes, this is correct and my code works equal. The problem is when I try to access to a slot outside from the method. In your test, you hit "1" in the menu and the value asigned is 14, this is correct. But If you hit "0" you will exit from menu and then If you print the value of the slot with print(x@competition) you will get 0 and not 14 like me :( I have write this before you add return(object). I'm gonna test it!!!

    – José Carlos
    Nov 13 '18 at 11:41







  • 1





    When setting say y to be myFun(x) I do have 14 in the competition slot - see above.

    – nate.edwinton
    Nov 13 '18 at 11:46











  • It works!!! Thank you so much @nate.edwinton!!!

    – José Carlos
    Nov 13 '18 at 11:49










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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279093%2fr-how-to-modify-values-of-slots%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









1














Okay so here are a couple of lines that helped for me:



myFun <- function(object) 0
setGeneric("myFun")
setClass("myClass", slots = c("competition", "stats"))


I then proceed with your code (slightly modified the the setMethod):



setMethod("myFun", "myClass", function(object)
while (TRUE)
#Clean console
cat("14")
cat("COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICIONn")
cat("-------------------------------------------------nn")
cat("1. Comparativa entre clubes de Liga DIAn")
cat("2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'n")
cat("3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'n")
cat("0. Salirnn")
option <- readline("Selecciona opción: ")
option <- suppressWarnings(as.numeric(option))
if (!is.na(option))
if (option == 1)
object@competition <- 14
break

if (option == 2)
object@competition <- 22
break

if (option == 3)
object@competition <- 23
break

print(object@competition)
readline("Espera ...")
if (option == 0)
break
else
readline("No es un número. Pulsa una tecla para introducir otra opción.")


return(object)
)


Here is my output:



x <- new("myClass", competition = 0, stats = 0)
# printing just x yields:
An object of class "myClass"
Slot "competition":
[1] 0

Slot "stats":
[1] 0

# Here is what myFun(x) yields:
COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICION
-------------------------------------------------

1. Comparativa entre clubes de Liga DIA
2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'
3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'
0. Salir

Selecciona opción:
# hits 1
An object of class "myClass"
Slot "competition":
[1] 14

Slot "stats":
[1] 0


Now setting y <- myFun(x), we obtain (again hitting 1 in the console):



> print(y@competition)
[1] 14





share|improve this answer

























  • Yes, this is correct and my code works equal. The problem is when I try to access to a slot outside from the method. In your test, you hit "1" in the menu and the value asigned is 14, this is correct. But If you hit "0" you will exit from menu and then If you print the value of the slot with print(x@competition) you will get 0 and not 14 like me :( I have write this before you add return(object). I'm gonna test it!!!

    – José Carlos
    Nov 13 '18 at 11:41







  • 1





    When setting say y to be myFun(x) I do have 14 in the competition slot - see above.

    – nate.edwinton
    Nov 13 '18 at 11:46











  • It works!!! Thank you so much @nate.edwinton!!!

    – José Carlos
    Nov 13 '18 at 11:49















1














Okay so here are a couple of lines that helped for me:



myFun <- function(object) 0
setGeneric("myFun")
setClass("myClass", slots = c("competition", "stats"))


I then proceed with your code (slightly modified the the setMethod):



setMethod("myFun", "myClass", function(object)
while (TRUE)
#Clean console
cat("14")
cat("COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICIONn")
cat("-------------------------------------------------nn")
cat("1. Comparativa entre clubes de Liga DIAn")
cat("2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'n")
cat("3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'n")
cat("0. Salirnn")
option <- readline("Selecciona opción: ")
option <- suppressWarnings(as.numeric(option))
if (!is.na(option))
if (option == 1)
object@competition <- 14
break

if (option == 2)
object@competition <- 22
break

if (option == 3)
object@competition <- 23
break

print(object@competition)
readline("Espera ...")
if (option == 0)
break
else
readline("No es un número. Pulsa una tecla para introducir otra opción.")


return(object)
)


Here is my output:



x <- new("myClass", competition = 0, stats = 0)
# printing just x yields:
An object of class "myClass"
Slot "competition":
[1] 0

Slot "stats":
[1] 0

# Here is what myFun(x) yields:
COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICION
-------------------------------------------------

1. Comparativa entre clubes de Liga DIA
2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'
3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'
0. Salir

Selecciona opción:
# hits 1
An object of class "myClass"
Slot "competition":
[1] 14

Slot "stats":
[1] 0


Now setting y <- myFun(x), we obtain (again hitting 1 in the console):



> print(y@competition)
[1] 14





share|improve this answer

























  • Yes, this is correct and my code works equal. The problem is when I try to access to a slot outside from the method. In your test, you hit "1" in the menu and the value asigned is 14, this is correct. But If you hit "0" you will exit from menu and then If you print the value of the slot with print(x@competition) you will get 0 and not 14 like me :( I have write this before you add return(object). I'm gonna test it!!!

    – José Carlos
    Nov 13 '18 at 11:41







  • 1





    When setting say y to be myFun(x) I do have 14 in the competition slot - see above.

    – nate.edwinton
    Nov 13 '18 at 11:46











  • It works!!! Thank you so much @nate.edwinton!!!

    – José Carlos
    Nov 13 '18 at 11:49













1












1








1







Okay so here are a couple of lines that helped for me:



myFun <- function(object) 0
setGeneric("myFun")
setClass("myClass", slots = c("competition", "stats"))


I then proceed with your code (slightly modified the the setMethod):



setMethod("myFun", "myClass", function(object)
while (TRUE)
#Clean console
cat("14")
cat("COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICIONn")
cat("-------------------------------------------------nn")
cat("1. Comparativa entre clubes de Liga DIAn")
cat("2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'n")
cat("3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'n")
cat("0. Salirnn")
option <- readline("Selecciona opción: ")
option <- suppressWarnings(as.numeric(option))
if (!is.na(option))
if (option == 1)
object@competition <- 14
break

if (option == 2)
object@competition <- 22
break

if (option == 3)
object@competition <- 23
break

print(object@competition)
readline("Espera ...")
if (option == 0)
break
else
readline("No es un número. Pulsa una tecla para introducir otra opción.")


return(object)
)


Here is my output:



x <- new("myClass", competition = 0, stats = 0)
# printing just x yields:
An object of class "myClass"
Slot "competition":
[1] 0

Slot "stats":
[1] 0

# Here is what myFun(x) yields:
COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICION
-------------------------------------------------

1. Comparativa entre clubes de Liga DIA
2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'
3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'
0. Salir

Selecciona opción:
# hits 1
An object of class "myClass"
Slot "competition":
[1] 14

Slot "stats":
[1] 0


Now setting y <- myFun(x), we obtain (again hitting 1 in the console):



> print(y@competition)
[1] 14





share|improve this answer















Okay so here are a couple of lines that helped for me:



myFun <- function(object) 0
setGeneric("myFun")
setClass("myClass", slots = c("competition", "stats"))


I then proceed with your code (slightly modified the the setMethod):



setMethod("myFun", "myClass", function(object)
while (TRUE)
#Clean console
cat("14")
cat("COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICIONn")
cat("-------------------------------------------------nn")
cat("1. Comparativa entre clubes de Liga DIAn")
cat("2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'n")
cat("3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'n")
cat("0. Salirnn")
option <- readline("Selecciona opción: ")
option <- suppressWarnings(as.numeric(option))
if (!is.na(option))
if (option == 1)
object@competition <- 14
break

if (option == 2)
object@competition <- 22
break

if (option == 3)
object@competition <- 23
break

print(object@competition)
readline("Espera ...")
if (option == 0)
break
else
readline("No es un número. Pulsa una tecla para introducir otra opción.")


return(object)
)


Here is my output:



x <- new("myClass", competition = 0, stats = 0)
# printing just x yields:
An object of class "myClass"
Slot "competition":
[1] 0

Slot "stats":
[1] 0

# Here is what myFun(x) yields:
COMPARATIVA ENTRE EQUIPOS DE LA MISMA COMPETICION
-------------------------------------------------

1. Comparativa entre clubes de Liga DIA
2. Comparativa entre clubes de Liga Femenina 2 - Grupo 'A'
3. Comparativa entre clubes de Liga Femenina 2 - Grupo 'B'
0. Salir

Selecciona opción:
# hits 1
An object of class "myClass"
Slot "competition":
[1] 14

Slot "stats":
[1] 0


Now setting y <- myFun(x), we obtain (again hitting 1 in the console):



> print(y@competition)
[1] 14






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 11:44

























answered Nov 13 '18 at 11:20









nate.edwintonnate.edwinton

1,650315




1,650315












  • Yes, this is correct and my code works equal. The problem is when I try to access to a slot outside from the method. In your test, you hit "1" in the menu and the value asigned is 14, this is correct. But If you hit "0" you will exit from menu and then If you print the value of the slot with print(x@competition) you will get 0 and not 14 like me :( I have write this before you add return(object). I'm gonna test it!!!

    – José Carlos
    Nov 13 '18 at 11:41







  • 1





    When setting say y to be myFun(x) I do have 14 in the competition slot - see above.

    – nate.edwinton
    Nov 13 '18 at 11:46











  • It works!!! Thank you so much @nate.edwinton!!!

    – José Carlos
    Nov 13 '18 at 11:49

















  • Yes, this is correct and my code works equal. The problem is when I try to access to a slot outside from the method. In your test, you hit "1" in the menu and the value asigned is 14, this is correct. But If you hit "0" you will exit from menu and then If you print the value of the slot with print(x@competition) you will get 0 and not 14 like me :( I have write this before you add return(object). I'm gonna test it!!!

    – José Carlos
    Nov 13 '18 at 11:41







  • 1





    When setting say y to be myFun(x) I do have 14 in the competition slot - see above.

    – nate.edwinton
    Nov 13 '18 at 11:46











  • It works!!! Thank you so much @nate.edwinton!!!

    – José Carlos
    Nov 13 '18 at 11:49
















Yes, this is correct and my code works equal. The problem is when I try to access to a slot outside from the method. In your test, you hit "1" in the menu and the value asigned is 14, this is correct. But If you hit "0" you will exit from menu and then If you print the value of the slot with print(x@competition) you will get 0 and not 14 like me :( I have write this before you add return(object). I'm gonna test it!!!

– José Carlos
Nov 13 '18 at 11:41






Yes, this is correct and my code works equal. The problem is when I try to access to a slot outside from the method. In your test, you hit "1" in the menu and the value asigned is 14, this is correct. But If you hit "0" you will exit from menu and then If you print the value of the slot with print(x@competition) you will get 0 and not 14 like me :( I have write this before you add return(object). I'm gonna test it!!!

– José Carlos
Nov 13 '18 at 11:41





1




1





When setting say y to be myFun(x) I do have 14 in the competition slot - see above.

– nate.edwinton
Nov 13 '18 at 11:46





When setting say y to be myFun(x) I do have 14 in the competition slot - see above.

– nate.edwinton
Nov 13 '18 at 11:46













It works!!! Thank you so much @nate.edwinton!!!

– José Carlos
Nov 13 '18 at 11:49





It works!!! Thank you so much @nate.edwinton!!!

– José Carlos
Nov 13 '18 at 11:49

















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279093%2fr-how-to-modify-values-of-slots%23new-answer', 'question_page');

);

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







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党