gama-platform / gama.old

Main repository for developing the 1.x versions of GAMA
GNU General Public License v3.0
304 stars 99 forks source link

Can not access variables defined in experiment in interactive console #3868

Closed LorisHenry closed 1 year ago

LorisHenry commented 1 year ago

Describe the bug When defining a variable in an experiment, we can not access the variable in the interactive console

To Reproduce Steps to reproduce the behavior:

code to reproduce :

//
model issueexpe

global {
    int var2;
}

experiment main {
    int var1;
}
//

Then in the interactive console type :

var1

Expected behavior should return 0 but returns Error: Block definition does not begin or end correctly Typing var2 returns 0 because defined in global

Likewise for "var1;", "experiment.var1", "main.var1", "experiment[0].var1", "main[0].var1"

Screenshots If applicable, add screenshots to help explain your problem.

hqnghi88 commented 1 year ago

AFAIK, it is a new feature (very experimental), that the GUI is link to separated simulation (if you have multi) and as effect, it distingue with experiment scope. See the color in Interactive console, it the same with current chosen simulation

image

So var1 is not in simulation scope. it you chose the experiment GUI scope (small triangle)

image

And it return the right scope and value for var1

image

BUT it strange the in simulation scope, your Likewise syntax did not work or some other like: host.var1,

AlexisDrogoul commented 1 year ago

Hi. The new version presented by Nghi partially solves this issue: you are now able to explicitly target the experiment as the agent with which one interacts in the console. However, two still remain if you enter experiment.var1 in the console while talking with the simulation:

  1. it raises an error that has nothing to do with the context (the one you mention, Error: Block definition does not begin or end correctly)
  2. it does not find var1.

Both are due to the fact that we have to deal with a compilation (and not execution) error: when an expression like experiment.var1 is compiled, GAML does not know which experiment species we are targeting. However, when it is executed, the context is the one of the current experiment. That is why experiment.var1 returns an error (albeit a bit obscure) but experiment["var1"] not (and returns the correct value). In the latter, no verification is made at compilation time about the existence of var1, assuming that if it does not exist, nil will be returned at execution time.

I will try to implement and push a solution where

  1. The compilation error is correctly written in the console (not just a wrong error message)
  2. The current experiment context is retrieved when a GAML text is compiled in the context of a running experiment