ID:2034028
 
(See the best response by Kaiochao.)
Code:
var/ball = new/obj/red_ball
src << output(ball, "grid1: 1,1")


Problem description: I am trying to add an object to a cell of a grid. For that, I make an instance of it and add it like the above code. It works fine, the object is displayed on the cell but I am trying as soon as it is clicked a message to be printed, which does not work if I click it from the grid. If I added it normally from the map then it does print... I use:

obj
red_ball
icon = 'ball.dmi
Click()
world << "Test"


I think it'd help if you showed the whole snippet (everything having to do with creating and adding the ball to the grid).

What I think is happening, is after you add the ball to the grid, it is being deleted [via garbage collection] and doesn't actually exist anymore, hence clicking not working.
Best response
Skin reference:
Very important: If you send an atom to a grid like you would with a statpanel, keep that object in a list or make sure it actually exists somewhere in the world. Do not use a temporary object that will be deleted when the proc ends, or it can disappear/change in the grid when a new object is created. Statpanels don't have this problem because of the way they update, but it's a good idea even there not to use temporary atoms.

Your ball is created in the proc and only has a reference inside the proc. When the proc ends, all references to it are lost, so the garbage collector deletes the ball object, so although the grid appears to contain the ball, the ball doesn't actually exist, so the Click() doesn't exist.
Pretty much the above, I am using the first code inside a verb as I do need a verb for the player to add balls to the inventory...

mob
player
icon = 'player.dmi'
verb
add_ball()
var/ball = new/obj/red_ball
src << output(ball, "grid1: 1,1")
obj
red_ball
icon = 'ball.dmi
Click()
world << "Test"
In response to RedAndBlack
Something similar to this should get you going:

mob
player
var
tmp/balls[]

verb/add_ball()
if(!balls)
balls = list()

balls += new/obj/red_ball
refresh_balls_grid()

proc/refresh_balls_grid()
// no balls exist for this player...
if(!balls) return

var grid = 0
var obj/red_ball/r
for(r in balls)
src << output(r, "grid_control: 1, [++grid]")

winset(src, "grid_control", "cells = [grid]")