naming script

I know nothing about python but I was wondering if anyone has a script that does the following:

When a ray sensor detects an object and the E key is pressed the script needs to assign a string property the name of the object that triggered the sensor, also, there are 6 spring properties could the script assign it to the next in line (i.e. if property 1 has a value already put the name is property 2 and so on)?

I think it can be done. I am just unsure on how to go about the assigning to a different prop each time.

Hi I have made a portion of script that does something similar to the first part of your question. hopefully you can adapt it or find someone to adapt it for you. I have added some explanations to what I did.
Note I wrote this code for blender 2.8 so the code may be deprecated but should still work.

G = GameLogic
C = G.getCurrentController()
pickw = C.getSensor("pickweap") # this is a collision sensor

if pickw.isPositive():
    item = pickw.getHitObject()
    #get collision objects name and display it
    n = item.getName()
    name = '"'+n[2:]+'"' #the string setproperty actuator only accepts names without the default 'OB' prefix that blender adds this removes it
    prop = C.getActuator("prop") # this is a set property actuator on a realtime text plane
    prop.setValue(name) #set the property to be the name of the collision object
    G.addActiveActuator(prop, True) # activate actuator

Thanks for the script, what do I have to do to use it? do i put it on a python controller and hook it up to the ray and keyboard sensors? or are they already in the script? also do I need to rename anything in the script (properties to look for object names etc.)?

I have attached a blend with the script in action.
use W to move
A to turn left and D to turn right
bump into the other boxes to display the object names.
Hope this helps


nameobjects.blend (153 KB)

I understand it now thanks