• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM SOLVED switch statement doesnt seem to trigger in create event

F

fxokz

Guest
I'm trying to assign a random first and last name variable to a newly created object but I cant seem to get it to work. the variables just stay at -4. When I try putting the switch statement in the step event it works fine (but changes values every step...) not sure how to handle this.

the code below generates an object and sets a type var via controller object.
Code:
var inst = instance_create(1, 1, obj_customer);
inst.type = argument0;


the code below is the create event of the customer object.. the switch statement doesn't go through.
Code:
type = noone;
firstName = noone;
lastName = noone;

switch(type)
{
    case reg:
    firstName = global.firstNames[reg, irandom_range(0, array_length_2d(global.firstNames, reg) - 1)];
    lastName = global.lastNames[reg, irandom_range(0, array_length_2d(global.lastNames, reg) - 1)];
    break;
    
    case sus:
    firstName = global.firstNames[sus, irandom_range(0, array_length_2d(global.firstNames, sus) - 1)];
    lastName = global.lastNames[sus, irandom_range(0, array_length_2d(global.lastNames, sus) - 1)];
    break;
    
    case cop:
    firstName = global.firstNames[cop, irandom_range(0, array_length_2d(global.firstNames, cop) - 1)];
    lastName = global.lastNames[cop, irandom_range(0, array_length_2d(global.lastNames, cop) - 1)];
    break;
}
 

Simon Gust

Member
The create event happens before values are assigned where you create the instance via code.
Use a with statement and put in the whole code you have there.
 
Top