ID:2841290
 
(See the best response by Ter13.)
Code:
```
var value = 444

mob/Login()
Example(&value)
world << "value: [value]"

proc/Example(value)
*value = 333
Example2(&value)

proc/Example2(value)
*value = 222
```


Problem description:

Trying to create something but having issues with pointers, so the reference/pointer to them is lost after a single proc call?

The above outputs value: 333 when I think it should return 222, however if I just pass the variable without & or * it causes it to output
&NORTH and <prob[1].x>


var/smart_variables/sv = new

smart_variables
var pref
var list/refs
New()
refs = new/list(128)
spawn()
var tick = world.tick_lag
var ref, list/l
for()
sleep(tick)
for(ref in refs)
if(!ref){continue}
world << "[ref[1]] vs [*ref[2]]"
if(*ref[2] != ref[1])
ref[1] = *ref[2]
switch(ref:len)
if(3)
call(ref[3])(ref[1])

proc/follow_changes(variable,function)
sv.refs[++sv.pref] = list(*variable, &variable, /proc/Example)


Trying to create a datum that contains a list such as the pointer to the variable so I can loop and find if said variable's value has changed so that I may call a function.

Trying to create a better version of this

Best response
Example's value parameter is already a pointer when you pass it to Example2, so you don't need to use &value when you pass it to Example2.

var value = 444

mob/Login()
Example(&value)
world << "value: [value]"

proc/Example(value)
*value = 333
Example2(value)

proc/Example2(value)
*value = 222


This will perform as you expect.
In response to Ter13
Ter13 wrote:
Example's value parameter is already a pointer when you pass it to Example2, so you don't need to use &value when you pass it to Example2.

Damn
A good way to avoid trouble with pointers is to use a naming scheme to help remember. Prevacing the var name with p can be enough, like proc/Example(pvalue), to remind you it's a pointer.
As I understand it, that's because, with the way you had it before, you make a pointer to a pointer.

*value in Example2 accesses the variable 'value' in Example, which contains the pointer to the global variable 'value'.

So e.g. **value would access the global variable, and *value=222 changes the Example variable so it holds 222 instead of holding the pointer to the global 'value'.