Forum Discussion
6 Replies
- Smuggler3MHCP Member
Dax! Punctuation is free-u don't have to spend any money to use periods, commas, apostrophes, or question marks!
Try this workaround: Make the colors be wallpaper or a texture. Put a big number on each button but make the number transparent. The player will see the color, push the button. The game engine will recognize, or might recognize that a number has been pushed.
Reply back if that works. Also, if it doesn't.
Nice to meet u!
- OverTheEdgeMHCP Member
What sort of functionality did you have in mind?
Is the password 4 entries long?
Does the combination lock wait until the (4) entries are made and before it tells you whether or not the code is right?
Or does it recognize when an incorrect entry is made along the way and reset?
I imagine you could have 1 master script and another script with variables that you can enter in the editor used on each of he colored buttons.
Every time you press a button, you send a number associated with that color button to the master script at the current slot. Every time you make an entry, you increment the slot. Meaning, if you are having an issue with strings, you could create 4 separate number variables instead (entry 1, entry 2, entry 3, entry 4) that you fill and then you could compare those with what number you expect. This feels hacky but this is a version made up of nested conditionals.import * as hz from "horizon/core"; export class EntryChecker extends hz.Component { entry1: number = 0; // First number entered by the player entry2: number = 0; // Second number entered by the player entry3: number = 0; // Third number entered by the player entry4: number = 0; // Fourth number entered by the player numberOfEntries: number = 0; // Tracks how many entries have been submitted openDoor: boolean = false; // Flag used to determine if the correct sequence was entered start () { } // This method can be called from another script to add an entry registerEntry(): void { this.numberOfEntries++; // Increment the number of entries each time this function is called if (this.numberOfEntries === 4) { // Once 4 entries have been made, call the checkCombination() function // This function checks if the player-entered values match the expected sequence this.checkCombination(); } } // Internal method to verify if the correct sequence was entered private checkCombination(): void { // Check all 4 entries against the hardcoded expected sequence: // 3 is the expected 1st number // 2 is the expected 2nd number // 4 is the expected 3rd number // 1 is the expected 4th number const correct = this.entry1 === 3 && this.entry2 === 2 && this.entry3 === 4 && this.entry4 === 1; if (correct) { this.openDoor = true; // Success: open the door } else { this.numberOfEntries = 0; // Failure: reset and try again } } } hz.Component.register(EntryChecker);- Smuggler3MHCP Member
Hey SeeJay,
What language/script is that (what you posted above)? Thx.- OverTheEdgeMHCP Member
Typescript > But I haven't checked that in the editor. Its just a guide for an approach.
- FreakyChestMHCP Member
Just worked with another creator to do this, use array to hold correct code/color (["blue", "red"] or just use numbers. Use index so you can track which one you are currently picking for, once player selects (we used triggers for selection) you check if it is correct code/color if not you can set to incorrect and reset it, or you can have a boolean that you change to false if any are incorrect and tell them at end once all are selected as well.
- FreakyChestMHCP Member
The following code works for a password system, you will still want to add delay so that trigger doesn't get hit twice on accident. But this would work as is, just have the colors and put a trigger around it, then set the trigger to one of the trigger props. You can just add code in correctPassword to do something when they do something right. You can also replace the log that says incorrect answer and do something there if you want a sound or so (so player knows they did a wrong password).
import { Component, PropTypes, CodeBlockEvents, Player, SpawnPointGizmo, Entity, EntityInteractionMode, TriggerGizmo } from "horizon/core"; class Triggers extends Component<typeof Triggers> { static propsDefinition = { trigger0: { type: PropTypes.Entity }, trigger1: { type: PropTypes.Entity }, trigger2: { type: PropTypes.Entity } }; sequence:number[]=[]; sequenceIndex = 0; start() { this.setSequence(); if(!this.props.trigger0 || !this.props.trigger1 ||!this.props.trigger2){ console.error("A trigger is undefined"); return; } this.connectCodeBlockEvent(this.props.trigger0, CodeBlockEvents.OnPlayerEnterTrigger,(player:Player)=>{ //if(this.props.trigger0) this.props.trigger0.as(TriggerGizmo)?.enabled.set(false); console.log("trigger 0") this.addInput(0) }) this.connectCodeBlockEvent(this.props.trigger1, CodeBlockEvents.OnPlayerEnterTrigger,(player:Player)=>{ //if(this.props.trigger1) this.props.trigger1.as(TriggerGizmo)?.enabled.set(false); console.log("trigger 1") this.addInput(1) }) this.connectCodeBlockEvent(this.props.trigger2, CodeBlockEvents.OnPlayerEnterTrigger,(player:Player)=>{ //if(this.props.trigger2) this.props.trigger2.as(TriggerGizmo)?.enabled.set(false); console.log("trigger 2") this.addInput(2) }) } correctPassword(){ console.log("Correct passord was entered"); this.resetUserInput(); } addInput(index:number){ console.log("addInput", index) if(index == this.sequence[this.sequenceIndex]){ this.sequenceIndex++; console.log("correct") }else{ console.log("incorrect answer:",this.sequence[this.sequenceIndex] ) this.resetUserInput(); } if(this.sequenceIndex>=3){ this.correctPassword(); } } resetUserInput(){ console.log("User input reset"); this.sequenceIndex =0; if(this.props.trigger0) this.props.trigger0.as(TriggerGizmo)?.enabled.set(true); if(this.props.trigger1) this.props.trigger1.as(TriggerGizmo)?.enabled.set(true); if(this.props.trigger2) this.props.trigger2.as(TriggerGizmo)?.enabled.set(true); } setSequence(){ this.sequence = [0,1,2] } } Component.register(Triggers);