Random Actuator -- Hello!! and HELP ME!!

Hello, i am new to the forums and i would like to say hello to everybody in this nice community, but i need help.
I am developing in the BGE and i know a few things but i know i am a rookie.
The thing is that i want to make random enemies spawn at random spawn points… my only problem is that i cannot control the Random Actuator, my plan was to give it a different seed everytime with python to get always different experiences even playing the same level. But the Random Actuator seems to ignore what i tell it to do. I have tried this:

#— Contr is the current controller, and RandomGen1 and 2 are the 2 random actuators.

contr.actuators['RandomGen1'].seed = contr.owner['SpawnSeedGen']
contr.actuators['RandomGen2'].seed = contr.owner['EnemySelSeed']
contr.actuators['RandomGen2'].setIntUniform(1, int(GV['Level_To_Load']))

And it does not work, the actuators keep their hand written values. No msgs on the console, no deprecated warnings, NOTHING!!

By the way i am activating the actuators directly by python scripting.

#-- Example
contr.activate(contr.actuators[‘RandomGen1’])

This seems fairly simple and the random numbers are generated but the actuators ignore all the parameters i passed them, however i know the script is working because the only thing triggering those actuators is that same script.

I don’t know what is wrong… HELP :frowning:

I’d go an entirely different route…

The random actuators don’t actually generate random numbers. They’ll generate the same numbers each time you run the game. The 5th number generated by the random actuator on one playthrough will be the exact same number as the 5th number generated on the second playthrough.

Use python’s random module instead. Simply input it (input random) and you’re set. Now you can use random.randint(lownum, highnum) for ints, random.uniform(lownum,highnum) for random floats, etc.

-Sam

First of all… THANKS!!! This one seems to listen to me but it gave me the same number everytime… (just one fixed result)

I did the following:

#-- Importing The Random Module
import random
#-- Geting the current controller
contr = GameLogic.getCurrentController()
#-- Inputing The Seed
random.seed(contr.owner[‘Seed’])
#-- Setting The Range and getting the results
contr.owner[‘MyRND’] = random.randint(1, 10)
#-- Changing Seed
contr.owner[‘Seed’] = contr.owner[‘Seed’] + contr.owner[‘MyRND’] + contr.owner[‘MyRND’]

I was thinking: Maybe i should generate a list of elements and use random.shuffle
and random.choice but then i came up with this:

#-- Importing The Random Module
import random
#-- Geting the current controller
contr = GameLogic.getCurrentController()
#-- Inputing The Seed
random.seed(contr.owner[‘Seed’])
#-- Setting The Range and getting the results
contr.owner[‘MyRND’] = random.randint(1, 10)
#-- Changing Seed
#-- But instead of changing the seed manually i made this var a timer var

That seems to work but…
-Can i have problems with that timer running for a long long time?
-Should i put the random.py module in the same directory to test the game in other machines, or any machine that will run this needs to have Python Installed?

Nonono… you don’t need to seed anything with the random module. If you set a seed, then it will continue to generate the same number. For a more complete explaination, see the wikipedia article.

Be default, I believe the random module uses Time as a seed. This will allow you to generate different random numbers every time. You don’t need to manually do this.

The basic message here is: YOU DON’T NEED TO SET THE SEED! Just do:


import random
import GameLogic as g
own = g.getCurrentController().owner

random.seed(5)
own['test'] = random.randint(0,10)

Also… I know that you’re just getting into programming, but commenting every line is unnecessary. You don’t need to reveal what each line does unless it’s not obvious from reading the code. For example:

 
import random

This obviously imports the random module. It’s very clear that that’s what it’s supposed to do. Same with getCurrentController.

Comments that simply restate what that line does aren’t useful and just take up space.

Just a tip!

In terms of where to put the random.py module, in the directory should work fine.

-Sam

Well, you are right, but with the comments i was just trying to make this posts useful for other people.

Anyway you were right, i did this:

import random

contr = GameLogic. getCurrentController()

contr.owner[‘Result’] = random.randint(1,10)

#-- To check all the results to see when it starts again (Just to see the list of results)
print contr.owner[‘Result’]

And everytime you start the game he gives you a different sequence of numbers…

Thank you for your tips…
Thank you very much bro. Problem Solved Here